neo4j docker connection failure

  • Last Update :
  • Techknowledgy :

‎05-14-2020 09:38 PM , ‎05-14-2020 02:19 PM , ‎07-20-2020 05:55 PM , ‎07-20-2020 04:38 AM

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)

@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:

Suggestion : 2
  • IF both are running in two different container use Docker-compose and you will able to access new4j database from container name like neo4j:port thats it.
  • If new4j running on the host, then you need to access new4j using the HOST ip inside your python container.
  • If you you do not want to use docker-compose, you can use lagacy linking
 docker run - d - P--name web--link newdb: db training / webapp python app.py

if you're running python inside a container use:

    GraphDatabase.driver(host="<contaniner>", auth=basic_auth("neo4j", "myPass"))

Suggestion : 3

I have a feeling that error could be caused by a browser setting. Could you start a neo4j container without mounting anything:,@TravelingTechGuy The docker run command you provided should work without needing to modify the conf (assuming the database in $HOME/neo4j/data isn't broken somehow).,Can you connect with the browser if you start neo4j like this?,@TravelingTechGuy I showed your issue to our browser and drivers teams and they think it's caused by the address 0.0.0.0 being automatically resolved to localhost in Unix, but not Windows.

docker run\
--publish = 7474: 7474--publish = 7687: 7687\
   --volume = $HOME / neo4j / data: /data \
   --env = NEO4J_AUTH = none\
   --env SECURE_FILE_PERMISSIONS = yes\
   --name my_neo4j\
neo4j
docker run\
--publish = 7474: 7474--publish = 7687: 7687\
   --env = NEO4J_AUTH = none\
neo4j
SessionExpired: WebSocket connection failure.Due to security constraints in your web browser, the reason
for the failure is not available to this Neo4j Driver.Please use your browsers development console to determine the root cause of the failure.Common reasons include the database being unavailable, using the wrong connection URL or temporary network problems.If you have enabled encryption, ensure your browser is configured to trust the certificate Neo4j is configured to use.WebSocket `readyState`
is: 3
SCRIPT12029: SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established
Firefox can’ t establish a connection to the server at ws: //0.0.0.0:7687/. neo4j-driver.chunkhash.bundle.js:1:2423
   Source map error: Error: request failed with status 404
Resource URL: http: //localhost:7474/browser/
   Source Map URL: .. / sourcemaps / inpage.js.map
WebSocket connection to 'ws://0.0.0.0:7687/'
failed: Error in connection establishment: net::ERR_ADDRESS_INVALID
r @ neo4j - driver.chunkhash.bundle.js: 1

Suggestion : 4

From the comment, I assume the neo4j anycodings_neo4j-driver Database is running in other containers.,You can not connect from one container anycodings_neo4j-driver to another container using URL anycodings_neo4j-driver localhost.,Localhost always refers to the localhost anycodings_neo4j-driver of the current container not the other anycodings_neo4j-driver container call it B.,IF both are running in two different container use Docker-compose and you will able to access new4j database from container name like neo4j:port thats it.

Error message:

    Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 835, in _connect
    s.connect(resolved_address)
OSError: [Errno 99] Cannot assign requested address

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    driver = GraphDatabase.driver(uri, auth=("neo4j", "admin"))
  File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 116, in driver
    return Driver(uri, **config)
  File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 157, in __new__
    return subclass(uri, **config)
  File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 231, in __new__
    pool.release(pool.acquire())
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 719, in acquire
    return self.acquire_direct(self.address)
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 612, in acquire_direct
    connection = self.connector(address, error_handler=self.connection_error_handler)
  File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 228, in connector
    return connect(address, **dict(config, **kwargs))
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 976, in connect
    raise last_error
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 966, in connect
    s = _connect(resolved_address, **config)
  File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 847, in _connect
    raise ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error))
neobolt.exceptions.ServiceUnavailable: Failed to establish connection to ('::1', 11010, 0, 0) (reason [Errno 99] Cannot assign requested address)

The code I used is as follows:

from neo4j
import GraphDatabase
uri = "bolt://localhost:11010/"
driver = GraphDatabase.driver(uri, auth = ("neo4j", "admin"))
with driver.session() as session:
   result = session.run("MATCH (n) RETURN count(n)")
print(result)
session.close()

And my docker file is as follows:

FROM python: 3
ADD test.py /
   RUN pip install pandas
RUN pip install pymysql
RUN pip install sqlalchemy
RUN pip install neo4j
CMD["python", "test.py"]
  • IF both are running in two different container use Docker-compose and you will able to access new4j database from container name like neo4j:port thats it.
  • If new4j running on the host, then you need to access new4j using the HOST ip inside your python container.
  • If you you do not want to use docker-compose, you can use lagacy linking
 docker run - d - P--name web--link newdb: db training / webapp python app.py

if you're running python inside a anycodings_neo4j-driver container use:

    GraphDatabase.driver(host="<contaniner>", auth=basic_auth("neo4j", "myPass"))

Suggestion : 5

Cannot Connect To Neo4j Database On Docker Container,On the docker neo4j container I see only:, 1 week ago Web Nov 08, 2020  · This api is also containerized. Both the API and neo4j containers run with docker-compose. This works great on most machines but not the OPs. Printing the host right before the neo4j query shows the correct value (neo4j://graph_db:7687) where graph_db is the name of the neo4j container. , › See also: Database Docker


Traceback (most recent call last): File "/app/runserver.py", line 1, in <module> from orangebox import app File "/app/orangebox/__init__.py", line 5, in <module> from orangebox.context import ob File "/app/orangebox/context.py", line 2, in <module> from orangebox.domain.factory import DomainFactory File "/app/orangebox/domain/factory.py", line 4, in <module> from orangebox.domain.boxes import Box File "/app/orangebox/domain/boxes.py", line 3, in <module> from orangebox.domain.users import User File "/app/orangebox/domain/users.py", line 4, in <module> class User(StructuredNode): File "/app/src/neomodel/neomodel/core.py", line 65, in __new__ install_labels(inst) File "/app/src/neomodel/neomodel/core.py", line 15, in install_labels db.new_session() File "/app/src/neomodel/neomodel/util.py", line 119, in new_session if self.session.neo4j_version < (2, 0): File "/usr/local/lib/python2.7/site-packages/py2neo/core.py" , line 958, in neo4j_version return version_tuple(self.resource.metadata["neo4j_version"]) File "/usr/local/lib/python2.7/site-packages/py2neo/core.py" , line 213, in metadata self.get() File "/usr/local/lib/python2.7/site-packages/py2neo/core.py" , line 258, in get response=self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs) File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py" , line 966, in get return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs) File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py" , line 943, in __get_or_head return rq.submit(redirect_limit=redirect_limit, **kwargs) File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py" , line 433, in submit http, rs=submit(self.method, uri, self.body, self.headers) File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py" , line 362, in submit raise SocketError(code, description, host_port=uri.host_port) py2neo.packages.httpstream.http.SocketError: Connection refused

Suggestion : 6

Enter the cloned directory and run below: # For Neo4j Backend $ docker-compose -f docker-amundsen.yml up # For Atlas $ docker-compose -f docker-amundsen-atlas.yml up If it’s your first time, you may want to proactively go through troubleshooting steps, especially the first one related to heap memory for ElasticSearch and Docker engine memory allocation (leading to Docker error 137).,If the docker container doesn’t have enough heap memory for Elastic Search, es_amundsen will fail during docker-compose.,If when running the sample data loader you recieve a connection error related to ElasticSearch or like this for Neo4j: Traceback (most recent call last): File "/home/ubuntu/amundsen/amundsendatabuilder/venv/lib/python3.6/site-packages/neobolt/direct.py", line 831, in _connect s.connect(resolved_address) ConnectionRefusedError: [Errno 111] Connection refused ,Make sure you have at least 3GB available to docker. Install docker and docker-compose.

$ git clone--recursive https: //github.com/amundsen-io/amundsen.git
# For Neo4j Backend
$ docker - compose - f docker - amundsen.yml up

# For Atlas
$ docker - compose - f docker - amundsen - atlas.yml up
 $ python3 - m venv venv
 $ source venv / bin / activate
 $ pip3 install--upgrade pip
 $ pip3 install - r requirements.txt
 $ python3 setup.py install
 $ python3 example / scripts / sample_data_loader.py
    Traceback(most recent call last):
       File "/home/ubuntu/amundsen/amundsendatabuilder/venv/lib/python3.6/site-packages/neobolt/direct.py", line 831, in _connect
    s.connect(resolved_address)
    ConnectionRefusedError: [Errno 111] Connection refused