2

i want to save docker neo4j database,and then restart it to continue use the data. first i run the command to start neo4j

docker run --publish=7474:7474 --publish=7687:7687 --volume=/Users/wangyiran/project/testplatformV6/data/neo4j1 neo4j:3.0

after insert some data, i want to commit the changes i use docker ps to find the neo4j continer id 429a3584673b then i run the command to commit the change

docker commit 429a3584673b copy

i checked the images through docker images,the copy exits

but when i want to restart the copy image

docker start copy

the report

Error response from daemon: No such container: copy Error: failed to start containers: copy

王奕然
  • 3,891
  • 6
  • 41
  • 62

2 Answers2

2

docker commit saves a container as a new image, it doesn't create a copy of the container.

You can start a new container from your image using a similar command to the original run:

docker run --publish=7474:7474 --publish=7687:7687 --volume=/Users/wangyiran/project/testplatformV6/data/neo4j1 copy

All that changes is the image name, which you tagged copy when you committed it.

Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • thanks,but how can i create a copy of the container to save the data? – 王奕然 Oct 19 '16 at 09:15
  • 1
    If you write data into the container's file system (i.e. not a volume), then when you `commit` it does get saved to the image. Run a new container from the committed image and you will have the saved data. If you're saving data in a volume, that lives outside the container and you can use it with different containers, you don't need to commit a new image. – Elton Stoneman Oct 19 '16 at 09:22
  • thanks.i try to run 'docker run --publish=7474:7474 --publish=7687:7687 neo4j:3.0' and then change data,then run 'docker commit 100ab0a5db85 copy2',then i run 'docker run --publish=7475:7474 --publish=7688:7687 copy2',but i cannot find the data in port 7475, – 王奕然 Oct 19 '16 at 09:49
  • I found this question looking for a solution when I *deliberately want* to have data in container. The volume for data directory is in the way then. The solution is to [docker build](https://stackoverflow.com/a/76124538/653539) new image. – Tomáš Záluský Apr 27 '23 at 21:21
2

If you store the data in the file system of the Host OS and not on the container, you'll get your data when you start the copy image with the same volume parameter.

In fact, if you only commit a copy and restart the same database using the copy image just for the data, you don't even need to do it. Every single time you start the neo4j image using the command you posted on your question:

docker run --publish=7474:7474 --publish=7687:7687 --volume=/Users/wangyiran/project/testplatformV6/data/neo4j1 neo4j:3.0

You'll have a database container who uses the data stored in /Users/wangyiran/project/testplatformV6/data/neo4j1. If that's not the case, you'll need to modify your docker run command into something like:

docker run --publish=7474:7474 --publish=7687:7687 --volume=/Users/wangyiran/project/testplatformV6/data/neo4j1:/var/lib/neo4j/datadirectory neo4j:3.0

You should know that --volume works as: --volume /path/to/host/directory:/path/to/container/directory.

NOTE: I don't know the path of neo4j's data directory, but it's most probably not /var/lib/neo4j/datadirectory. You have to check that out and modify the last "docker run" command accordingly

ardilgulez
  • 1,856
  • 18
  • 19
  • thanks,i run this command docker run --publish=7474:7474 --publish=7687:7687 --volume=/Users/wangyiran/project/testplatformV6/data/neo4j1:/data neo4j:3.0,it work! – 王奕然 Oct 19 '16 at 10:21