I am running neo4j using Docker, all is good. I am now customising a neo4j image and loading data after the docker container has started. Part of this process involves executing a cypher script file using the cypher-shell. I have both a dockerfile and a docker-compose.yml file.
If I use the dockerfile on it's own and just do build and then run everything is working exactly as expected and my container spins with a pre-populated neo4j database.
If I use the docker-compose.yml with the 'build: .' option that then executes the dockerfile when it gets to the point of executing the cypher script using cypher-shell I get the error ' Database 'neo4j' is unavailable.' and that is all the message that I see.
This is my dockerfile
FROM neo4j:4.2.2
ENV NEO4J_HOME="/var/lib/neo4j"
ENV NEO4J_PASSWD=password
ENV NEO4J_apoc_import_file_enabled=true
ENV APOC_VERSION=4.2.0.1
# SHould look at copying this from a shared resource folder
ADD https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/${APOC_VERSION}/apoc-${APOC_VERSION}-all.jar ${NEO4J_HOME}/plugins
# Copy over generated dependency graph json file from shared resource folder
COPY Neo4j/Dependencies_Tree_Full_UnSorted.json ${NEO4J_HOME}/import/
# copy over cypher script from shared resource folder
COPY Neo4j/data_loader.cypher ${NEO4J_HOME}/import/
# set initial-password to start loading the data
# sleep for 20 secs for neo4j to start without any overlapping
CMD bin/neo4j-admin set-initial-password ${NEO4J_PASSWD} && \
bin/neo4j start && sleep 6 0 && \
if [ -f "${NEO4J_HOME}/import/data_loader.cypher" ]; then \
echo "starting data load ..." && \
cat ${NEO4J_HOME}/import/data_loader.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast && rm ${NEO4J_HOME}/import/* && \
echo "data load finished ..."; \
fi && tail -f /logs/neo4j.log
I was initially getting the error ' Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.' but this went away when I added
to my docker-compose.yml file to now be replaced with the 'Database 'neo4j' is unavailable.' error message. As you can see in the dockerfile I have also set a 60 second sleep period for the cypher-shell to wait in case it was a case of playing catchup but still no good.
As I say this is only happening when I use 'docker-compose up', everything is fine if I only use 'docker run'
This is starting to get very frustrating now, no idea what I did but the original error is now back again!
'Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.'
Please look at the logs and read the exact error that is happening and then analyze it to understand what exactly is the problem. After that look into possible ways of workaround that will eliminate the errors.