docker-neo4j
docker-neo4j copied to clipboard
Unable to persist state during docker build
I expected that I can modify the initial state of database in the Dockerfile
, e.g. creating some indexes. It seems, however, that the state that I persist during the build steps is lost, maybe due to the entrypoint script?
Steps to reproduce
Following Dockerfile:
FROM neo4j:4.0.4-enterprise
ENV NEO4J_ACCEPT_LICENSE_AGREEMENT yes
COPY neo4j.conf /conf/
COPY schema.cypher /
RUN neo4j-admin set-initial-password test \
&& neo4j start \
&& sleep 10 \
&& /bin/bash -c "cat /schema.cypher | cypher-shell -u neo4j -p test --format verbose" \
&& neo4j stop
Following schema.cypher
:
:begin
CREATE CONSTRAINT ON (node:SomeNode) ASSERT (w.uuid) IS NODE KEY;
:commit
CALL db.awaitIndexes(300);
The resulting database image, after a docker build -t <image> .
however is empty, without any indexes. If I run the RUN
steps manually in a Docker container, it works as expected.
Tested with both neo4j:4.0.4-enterprise
and neo4j:3.5.14-enterprise
.
What's the log output of the docker build? Neo4j needs to be started as the neo4j:neo4j
user, but your Dockerfile will be running it as root
, which might be causing problems.
Could you also try adding USER neo4j:neo4j
before your RUN
?
Sure:
---> Running in 05bf08ff960e
Changed password for user 'neo4j'.
Active database: graph.db
Directories in use:
home: /var/lib/neo4j
config: /var/lib/neo4j/conf
logs: /var/lib/neo4j/logs
plugins: /var/lib/neo4j/plugins
import: /var/lib/neo4j/import
data: /var/lib/neo4j/data
certificates: /var/lib/neo4j/certificates
run: /var/lib/neo4j/run
Starting Neo4j.
Started neo4j (pid 121). It is available at http://localhost:7474/
There may be a short delay until the server is ready.
See /var/lib/neo4j/logs/neo4j.log for current status.
0 rows available after 212 ms, consumed after another 0 ms
Added 1 constraints
0 rows available after 171 ms, consumed after another 0 ms
Stopping Neo4j.. stopped
Removing intermediate container 05bf08ff960e
---> e33d33c85441
Successfully built e33d33c85441
Adding the USER
directive didn't change anything. The contents of all the directories and logs are empty on start of the image (here e33d33c85441
)...
Hello @sdaschner, seems like you have the same isssue as here: https://github.com/neo4j/docker-neo4j/issues/166 Please try to follow this workaround and let us know if it works for you. Thanks.