我已经完成了 ssh 端口转发,它在我的本地监听 2000。所以该服务运行在 localhost:2000 上,它是 Neo4J 服务器。在我的本地,我可以通过提供 bolt://localhost:2000
使用 Neo4J 桌面连接 Neo4J 并可以查看数据。
但我无法在 docker 容器中与主机 bolt://localhost:2000 连接。
我看了这里的答案
From inside of a Docker container, how do I connect to the localhost of the machine?
我在 docker-compose.yml 中添加了额外的主机
flask_service:
build:
context: ./project
dockerfile: my_dockerfile
container_name: flask_container
stdin_open: true
tty: true
ports:
- 5000:5000
extra_hosts:
- "myhost:175.1.344.136"
175.1.344.136 是我的主机 IP
我在容器内同时使用了 bolt://175.1.344.136:2000
和 bolt://myhost:2000
但它没有连接。我也想知道哪个是正确的方法bolt://175.1.344.136:2000
或 bolt://myhost:2000
出现错误
2021-05-25T10:53:55+0000.060 [INFO] neo4j_proxy.__init__:74 (8:Thread-11) - NEO4J endpoint: bolt://myhost:2000
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 831, in _connect
s.connect(resolved_address)
ConnectionRefusedError: [Errno 111] Connection refused
我使用的是 MacO,请帮我解决这个问题。
提前致谢!
答案 0 :(得分:-1)
您需要使用容器服务名称 neo4j 和默认端口 7687 在同一个 docker 主机中使用。
<块引用>bolt://neo4j:7687
version: "3.8"
services:
neo4j:
image: neo4j:3.4.4-enterprise
ports:
- 7474:7474
- 7687:7687
my_service:
build:
context: .
environment:
DATABASE_URL: "bolt://neo4j:7687"