Unable to access distant neo4j from my docker fastapi app

Viewed 37

I have 2 things : a neo4j database which is deployed on GCP compute engine at this IP bolt://35.241.254.136:7687

And I have a fastapi app that need to access to neo4j.

When I run the API server with uvicorn main:app --reload, all is working correctly. I can access my distant database.

However when I run the api with docker (docker run -d --name mycontainer -p 80:80 myimage), it's impossible to access the neo4j database and I have this error

ServiceUnavailable( neo4j.exceptions.ServiceUnavailable: Couldn't connect to 35.241.254.136:7687 (resolved to ('35.241.254.136:7687',)):

Maybe something is wrong, I don't know about docker.

Here is my dockerfile

FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./ /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
1 Answers

Make sure your container can see the jeo4j IP (35.241.254.136).

Execute the container's bash:

docker exec -it mycontainer bash

then ping the url:

ping 35.241.254.136

If you cannot reach to the host, you need to put your container in same network with jeo4j.

This link may be helpful.

Related