Search code examples
dockerneo4jdockerfile

Create custom Neo4j Docker image with intial data from cypher file


I tried create an docker image of neo4j that already provide some data, when you start an container. For my approach I inherited from the neo4j docker image, added some data via the neo4j cypher shell. But when i build the image and run a container from it the data did not appear in the database but the custom password is set. This is my current dockerfile:

From neo4j:3.4
ENV NEO4J_AUTH=neo4j/password
COPY data.cypher /var/lib/neo4j/import/
USER neo4j
RUN bin/neo4j-admin set-initial-password password || true && \
    bin/neo4j start && sleep 5 && \
    cat /var/lib/neo4j/import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=password /var/lib/neo4j/bin/cypher-shell --fail-fast
CMD [neo4j]

I added also an match query to the data.cypher file to make sure that the shell added the data to neo4j. Maybe it has something to do that /data is defined as volume in the neo4j image?


Solution

  • I was using Bierbarbar's approach. I got it working after getting over the following two pitfalls:

    Firstly, $NEO4J_HOME/data was symlinked to /data, which seem to have permission issues. Changing the default data folder: by adding dbms.directories.data=mydata line to $NEO4J_HOME/conf/neo4j.conf fixed this.

    Secondly, make sure data.cypher file contains correct format for cypher-shell: 1) Semicolon is needed at the end of each cypher statemnt; 2) there are :begin and :commit commands in some versions (or all versions?) of cypher-shell