GreenAsJade
GreenAsJade

Reputation: 14685

How do I tell my dockerised Spring Boot Neo4J application to talk to my Neo4j server?

I have an "out of the box" Spring Data Neo4j application that works fine when talking to a Neo4j server running on my box. By "out of the box" I mean that the only config I have done in the app is specify the username and password for Neo4j.

The app (run with ./gradlew bootRun) works fine with a dockerised Neo4j server as well.

When I build a docker image of this app, it fails to connect to the Neo4j server, whether or not that is dockerised.

When it works, it says:

2019-01-18 12:58:49.311 INFO 18345 --- [ restartedMain] Driver : Direct driver instance 1080149308 created for server address localhost:7687

When it doesn't work, it says:

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

I've tried linking the two dockers (app and Neo4j docker) with --link. Same result.

I've tried composing them:

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

No joy.

I need to end up with a dockerised solution.

Upvotes: 0

Views: 1019

Answers (1)

Mike
Mike

Reputation: 164

See this answer which refers to MySQL but explains the networking issue.

From inside of a Docker container, how do I connect to the localhost of the machine?

Bottom line though, if you're on linux add --network="host" and if you're on windows or mac change the neo4j host in your Spring Boot configuration to be host.docker.internal. To do taht edit your application.properties or application.yml file.

spring.data.neo4j.uri=bolt://host.docker.internal:7687

Documentation for Spring Boot's Neo4j support is here.

https://docs.spring.io/spring-boot/docs/2.1.2.RELEASE/reference/htmlsingle/#boot-features-neo4j

Upvotes: 1

Related Questions