saadi
saadi

Reputation: 714

Neo4j docker-compose image refusing connection to application


I used to run Neo4j separately and then my application interacted with it as required. Now I am using docker-compose to run Neo4j.

Here's my portion of neo4j in docker file.

  neo4j:
    container_name: neo4j_container
    restart: always
    image: neo4j:3.5.3
    network_mode: "bridge"
    ports:
      - "7474:7474"
      - "6477:6477"
      - "7687:7687"
      - "7473:7473"
    environment:
      - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
      - NEO4J_dbms_security_procedures_unrestricted=apoc.*
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_dbms_shell_enabled=true
      - NEO4J_dbms_connector_http_listen__address=:7474
      - NEO4J_dbms_connector_https_listen__address=:6477
      - NEO4J_dbms_connector_bolt_listen__address=:7687
    volumes:
      - /usr/local/abc/temp:/var/lib/neo4j/import

The image of Neo4j I am using, as you can see is neo4j:3.5.3.
When I try to access neo4j after docker-compose up from localhost:7474, it works totally fine.
But when I try to access it through my application, it gives the following error

Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.<br>

Tried taking help from this question, but even that didn't help.
Here's the docker-compose ps output: enter image description here Please tell me if I am missing something?

Upvotes: 1

Views: 1540

Answers (1)

mchawre
mchawre

Reputation: 12268

You should use machine-ip:7687 in your application to connect to neo4j.

In your case neo4j is running in bridge networking mode, in which the container network is different from that of host network. So in order to access application running inside such container from outside world, you have to do port mapping which you did using ports: field in docker-compose.

Now I guess the application which is trying to access neo4j is also running in bridge networking mode. So putting localhost:7687 in your application will point to localhost of that container, but you want to connect to neo4j container port 7687 which we have already mapped to host network using ports option. In this case your neo4j port 7687 can e accessed using machine-ip:7687 from outside world.

Hope this helps.

Upvotes: 1

Related Questions