Neo4j local desktop access via a docker image

I have a windows local neo4j desktop database that is running with
neo4j@bolt://localhost:7687/neo4j

I am been given a docker image file that shows capability of GenAI agents for Neo4j . The instruction if the deployment says

1- modify the.env file

NEO4J_URI=neo4j://localhost:7687
NEO4J_PASSWORD=mypass
NEO4J_USERNAME=neo4j
OPENAI_API_KEY=sk-

in the docker-compose.yml file, there are also these lines

environment:
- NEO4J_URI=${NEO4J_URI-neo4j://host.docker.internal:7687}
- NEO4J_PASSWORD=${NEO4J_PASSWORD-password}
- NEO4J_USERNAME=${NEO4J_USERNAME-neo4j}
- OPENAI_API_KEY=${OPENAI_API_KEY-}

When i ran "docker compose up " command, it gives me error
ValueError: Could not connect to Neo4j database. Please ensure that the url is correct

When i asked the provider , he mentioned:

Localhost with docker containers isn't localhost like your machine, but the docker container itself...
Unfortunately, each OS has different ways of handling that, for example with MAC you can use: NEO4J_URI=neo4j://host.docker.internal:7687

can you help me what URL i have to put in .env file or in docker-compose file directly?

Based on this article, the host.docker.internal to access your host's localhost should work on windows as well.

The docker container environment variables look like they being set by environment variables. You could try just setting the docker values directly for now to see if it works.

- NEO4J_URI=neo4j://host.docker.internal:7687
- NEO4J_PASSWORD=mypass
- NEO4J_USERNAME=neo4j
- OPENAI_API_KEY=sk-

Hi Gary

Thank you very much.

it solved the problem.

1 Like