5

A docker container for Neo4j is started as per the documentation and working properly using the following command:

$ docker run \
    --detach \
    --publish=7474:7474 \
    --publish=7473:7473 \
    --publish=7687:7687 \
    --volume=$HOME/neo4j/data:/data \
    --volume=$HOME/neo4j/logs:/logs \
    --volume=$HOME/neo4j/ssl:/ssl \
    --ulimit=nofile=40000:40000 \
    --name=myname-neo4j \
    neo4j:3.1.1

When I attempt to perform a neo4j-admin dump of the database I get an error:

$ docker exec -ti myname-neo4j bin/neo4j-admin dump --database=graph.db --to=/home/name/myname.dump
command failed: the database is in use -- stop Neo4j and try again

However, if the Neo4j process is stopped, which seems to be the only way to free the database, the container closes. This appears to be the expected behavior from Docker. Therefore, it appears to be impossible to call neo4j-admin dump from within the container without the database being in use.

How can this be resolved while still using Docker?

5

1: Stop the container.

docker stop myname-neo4j

2: Remove the container

docker rm myname-neo4j

3: Run the container as interactive mode (-it) without the option (detach) and executing the shell ( /bin/bash ).

docker run \
--publish=7474:7474 \
--publish=7473:7473 \
--publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
--volume=$HOME/neo4j/ssl:/ssl \
--ulimit=nofile=40000:40000 \
--name=myname-neo4j \
-it \
neo4j:3.1.1 \
-c /bin/bash

Now you are inside the neo4j container without running Neo.

4: Check that neo is not up by visiting the URI endpoint in (http://yourhost:7474). You should see the "Unable to connect" message.

5: Dump your database

docker exec -ti myname-neo4j bin/neo4j-admin dump --database=graph.db --to=/home/name/myname.dump
  • For step 5, one can either perform then command as you stated it from a 2nd session outside the container. Or one can simply omit docker exec -ti myname-neo4j and run it from the bash prompt inside the container. – Gregyski Mar 17 '17 at 18:37
  • 1
    what if container is already running? I will lose all data I want to backup if I stop it – vladkras Jul 14 '17 at 10:24
  • It is strongly recommended to mount a volume for your data so that it can be persistent and independent of your neo4j container lifespan. (see: docs.docker.com/engine/tutorials/dockervolumes). If you didn't do that then do not use the -rm flag in the "docker run " command. Stop the container, commit the changes with docker commit and proceed to step 4. Or simply commit your docker container in an external shell before stopping it. – Juan Jul 14 '17 at 11:04
0

I had the same issue before, so I wrote this workaround to dump neo4j data and pull it outside the container to the host machine.

docker rm --force neo4j-dump

docker run \
--name neo4j-dump \
--env-file /storage/bin/.neo4j.env \
--mount type=bind,source=<neo4j_data_folder>,target=/data \
neo4j:3.1.1 bin/neo4j-admin dump --database=graph.db --to=/graph.db.dump

docker cp `docker ps -aqf "name=neo4j-dump"`:/graph.db.dump <target_dump_file>

docker rm --force neo4j-dump

This will create a new container and dump data instead of starting neo4j service, then copy the dump to the host, just update and to yours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.