如何让我的 dockerised Spring Boot Neo4J 应用程序与我的 Neo4j 服务器通信?
How do I tell my dockerised Spring Boot Neo4J application to talk to my Neo4j server?
我有一个 "out of the box" Spring Data Neo4j 应用程序,它在与我盒子上的 Neo4j 服务器 运行ning 通信时工作正常。 "out of the box" 我的意思是我在应用程序中完成的唯一配置是指定 Neo4j 的用户名和密码。
该应用程序(运行 与 ./gradlew bootRun)在 dockerised Neo4j 服务器上也能正常工作。
当我构建此应用程序的 docker 映像时,它无法连接到 Neo4j 服务器,无论该服务器是否 dockerised。
当它工作时,它说:
2019-01-18 12:58:49.311 INFO 18345 --- [ restartedMain] Driver : Direct driver instance 1080149308 created for server address localhost:7687
当它不起作用时,它说:
2019-01-18 02:27:53.760 INFO 1 --- [ main] Driver : Direct driver instance 707892422 created for server address localhost:7687
2019-01-18 02:27:54.100 INFO 1 --- [ main] ConnectionPool : Closing connection pool towards localhost:7687
[...]
Caused by: org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:7687
我已经尝试使用 --link 对两个 docker(应用程序和 Neo4j docker)进行 link 测试。结果相同。
我试过作曲:
version: '3'
services:
docker-neo:
image: neo4j:3.5
ports:
- 7687:7687
- 7474:7474
godojo:
image: com.greenasjade.j01/j01
depends_on:
- docker-neo
ports:
- 8081:8081
不开心。
我需要得到一个 docker 化的解决方案。
查看此答案,其中提到 MySQL 但解释了网络问题。
From inside of a Docker container, how do I connect to the localhost of the machine?
底线,如果你在 linux 添加 --network="host" 如果你在 windows 或 mac 更改 neo4j 主机在您的 Spring 启动配置中设为 host.docker.internal。为此,请编辑您的 application.properties 或 application.yml 文件。
spring.data.neo4j.uri=bolt://host.docker.internal:7687
SpringBoot 的 Neo4j 支持文档在这里。
https://docs.spring.io/spring-boot/docs/2.1.2.RELEASE/reference/htmlsingle/#boot-features-neo4j
我有一个 "out of the box" Spring Data Neo4j 应用程序,它在与我盒子上的 Neo4j 服务器 运行ning 通信时工作正常。 "out of the box" 我的意思是我在应用程序中完成的唯一配置是指定 Neo4j 的用户名和密码。
该应用程序(运行 与 ./gradlew bootRun)在 dockerised Neo4j 服务器上也能正常工作。
当我构建此应用程序的 docker 映像时,它无法连接到 Neo4j 服务器,无论该服务器是否 dockerised。
当它工作时,它说:
2019-01-18 12:58:49.311 INFO 18345 --- [ restartedMain] Driver : Direct driver instance 1080149308 created for server address localhost:7687
当它不起作用时,它说:
2019-01-18 02:27:53.760 INFO 1 --- [ main] Driver : Direct driver instance 707892422 created for server address localhost:7687
2019-01-18 02:27:54.100 INFO 1 --- [ main] ConnectionPool : Closing connection pool towards localhost:7687
[...]
Caused by: org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:7687
我已经尝试使用 --link 对两个 docker(应用程序和 Neo4j docker)进行 link 测试。结果相同。
我试过作曲:
version: '3'
services:
docker-neo:
image: neo4j:3.5
ports:
- 7687:7687
- 7474:7474
godojo:
image: com.greenasjade.j01/j01
depends_on:
- docker-neo
ports:
- 8081:8081
不开心。
我需要得到一个 docker 化的解决方案。
查看此答案,其中提到 MySQL 但解释了网络问题。
From inside of a Docker container, how do I connect to the localhost of the machine?
底线,如果你在 linux 添加 --network="host" 如果你在 windows 或 mac 更改 neo4j 主机在您的 Spring 启动配置中设为 host.docker.internal。为此,请编辑您的 application.properties 或 application.yml 文件。
spring.data.neo4j.uri=bolt://host.docker.internal:7687
SpringBoot 的 Neo4j 支持文档在这里。
https://docs.spring.io/spring-boot/docs/2.1.2.RELEASE/reference/htmlsingle/#boot-features-neo4j