cancel
Showing results for 
Search instead for 
Did you mean: 

Copy dump file to docker container and load it on startup

harald_pehl
Node Link

Hi,

I'd like to copy a dump file to a docker container and load it using neo4j-admin load as part of an extension script in my docker container.

In particular I have the following workflow

Start an empty Neo4j community instance:

docker run \
  --detach \
  --name=neo4j-analyse \
  --publish=7687:7687 \
  --volume=$PWD/data:/data \
  --env NEO4J_AUTH=neo4j/neo5j \
  neo4j

Run a process which populates the database

Stop the neo4j-analyse instance:

docker stop neo4j-analyse

Dump the data to a local file:

docker run --interactive --tty --rm \
  --volume=$PWD/data:/data \
  --volume=$PWD/dump:/dump \
  --user="$(id -u):$(id -g)" \
  neo4j \
  neo4j-admin dump --database=neo4j --to=/dump/db.dump

Build a Neo4j image which contains the dump file and populates the database at startup:

docker build --tag neo4j-model .

The directory for the docker build contains the dump file db.dump, the Dockerfile:

FROM neo4j

COPY db.dump /db.dump
COPY extension-script.sh /extension-script.sh
ENV EXTENSION_SCRIPT=/extension-script.sh

and the extension-script.sh:

#!/bin/sh
neo4j-admin load --from=/db.dump --database=neo4j --force

Start the final docker container:

docker run \
  --detach \
  --name=neo4j-model \
  --publish=7474:7474 --publish=7687:7687 \
  --env NEO4J_AUTH=none \
  --env NEO4J_dbms_read__only=true \
  neo4j-model

I can see in the log that the dump file is loaded and Neo4j is started. If I want to connect with the Neo4j browser, I get the following error:

ERROR DatabaseNotFoundError
Database "neo4j" is unavailable, its status is "offline."

What am I doing wrong? Any hints suggestions and ideas are highly appreciated!

Thanks Harald

3 REPLIES 3

harald_pehl
Node Link

I was able to solve my problem, using a custom entrypoint in my Dockerfile.

For those interested, here are links to the Dockerfile and the custom entrypoint:

Also when I use the second method of custom entrypoint, the data is loaded in the neo4j database but the container closes and I cannot open neo4j-browser at my localhost!!

naman
Node

Hey thanks, this works perfectly!!
The only issue is I cannot write to my database, so when i try setting
ENV NEO4J_dbms_read__only=false or ENV NEO4J_writable = true , I am unable to load the data as it gives me the error that neo4j is running, then when i run "neo4j stop" the same error still persists!