cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Unable to connect to neo4j from a docker instance

Layvier
Node Link

Hi all,

I have a Node.js application that connects to neo4j. Running it normally works well, I'm able to connect. However, when I run it inside Docker I run into this error:

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)

I'm using neo4j-driver v4.0.2, and Neo4j 4.0.3.

I created a repo to reproduce the issue: https://github.com/Layvier/test_neo4j

Am I missing something regarding Docker networking ?

I found this related issue with the python driver: https://github.com/neo4j/neo4j-python-driver/issues/251#issuecomment-420160271

Thanks for your help !

4 REPLIES 4

jggomez
Graph Voyager

Hi,

Where is the neo4j instance?? is this in the same container?? If neo4j is outside, the container can´t see its local server (because the container is isolate from the world, is similar to VM), you should have a neo4j server with public and visible IP. You can use neo4j sandbox if you want to test neo4j.

Thanks

@Layvier, could you solve your issue ?
I'm also unable to connect to my neo4j container from another container, while I have no issues connecting to the same neo4j container from my system cypher-shell or neo4j desktop.

---
version: '3.8'  

services:

  neo4j:
    build: ./neo4j_db
    ports:
      - 57473:7473  # HTTPS
      - 57474:7474  # HTTP
      - 57687:7687  # BOLT
    environment:
      #  https://neo4j.com/docs/labs/neo4j-streams/current/docker/#neo4j_streams_docker
      - NEO4J_dbms_ssl_policy_bolt_client__auth=NONE
      - NEO4J_dbms_ssl_policy_https_client__auth=NONE
      - NEO4J_dbms_security_procedures_unrestricted=apoc.*
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
      - NEO4J_AUTH=none

  api:
    build: ./api_server
    ports:
      - 54001:4001
    environment:
      - NEO4J_URI=bolt://neo4j:57687  # https://neo4j.com/docs/driver-manual/current/client-applications/#driver-configuration-examples
      - NEO4J_USER=neo4j
      - GRAPHQL_LISTEN_PORT=4001
      - GRAPHQL_URI=http://api:54001/graphql
    links:
      - neo4j
    depends_on:
      - neo4j

networks:
  default:

When querying my API server (apollo), I get

api_1 | 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 172.19.0.2:57687

  • I believe host and port to be fine
  • scheme is good, connection without encryption

Layvier
Node Link

@AdrienLemaire Hey, for me it was a host issue, I got the solution here: https://stackoverflow.com/questions/61807703/unable-to-connect-to-neo4j-from-a-docker-instance.
I'm not sure how it works with docker compose 😕

Thanks for the reply. Docker-compose already does host mapping, so my issue is different, sorry for posting in the wrong place. I created an issue at https://github.com/neo4j/docker-neo4j/issues/267