【问题标题】:Unable to connect to neo4j from a docker instance无法从 docker 实例连接到 neo4j
【发布时间】:2020-05-14 21:27:28
【问题描述】:

我有一个连接到 neo4j 的 Node.js 应用程序。运行它正常运行良好,我能够连接。但是,当我在 Docker 中运行它时,我遇到了这个错误:

Neo4jError: Failed to connect to server. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0. Caused by: connect ECONNREFUSED 127.0.0.1:7687
at newError (/usr/src/app/node_modules/neo4j-driver/lib/error.js:75:10)
at NodeChannel._handleConnectionError (/usr/src/app/node_modules/neo4j-driver/lib/internal/node/node-channel.js:229:41)
at Socket.emit (events.js:310:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)

我正在使用 neo4j-driver v4.0.2 和 Neo4j 4.0.3。

我创建了一个 repo 来重现该问题:https://github.com/Layvier/test_neo4j

我是否遗漏了有关 Docker 网络的内容?

我在 python 驱动程序中发现了这个相关问题:https://github.com/neo4j/neo4j-python-driver/issues/251#issuecomment-420160271

感谢您的帮助!

【问题讨论】:

    标签: node.js docker neo4j bolt


    【解决方案1】:

    您的 docker 映像在隔离网络中运行,因此它无法访问您的 neo4j localhost:7687

    在您的 javascript 文件中,尝试将您要连接的 url 更改为您的主机 IP,而不是 localhost。您可以通过运行ip addr show 找到它。

    更好的是,您可以使用 --add-host 标志 - add host to container example 将主机映射传递给您的容器

    docker run -it --add-host=neo4j:[your-host-ip] user/test-neo4j:latest
    

    然后您可以在 index.js 中使用 neo4j 而不是 localhost 进行连接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2021-09-22
      相关资源
      最近更新 更多