I'm using Docker Toolbox on OSX.
I've created a data volume container for storing persistent data: https://docs.docker.com/userguide/dockervolumes/#creating-and-mounting-a-data-volume-container.
I checked that this data is indeed stored on the boot2docker VM (created by docker-machine) and not on the container, so that it will persist. However "docker-machine restart " clears out this custom data on the vm.
I can't find documentation on what is happening. I found one forum post mentioning that data in /var/lib/docker will be preserved, but I could not find any official docs stating that and it also seems strange considering the persistent storage guide above doesn't use this path or even mention that your data will be deleted.
Is this expected and if so is there any official documentation on the correct path to store persistent data?
Edit: Adding example of failing senario
$ docker-machine ssh alt
docker@alt:~$ docker run -v /data:/var/lib/mysql --name mydata busybox sh -c "echo 'hello' > /var/lib/mysql/hello"
docker@alt:~$ docker run --rm --volumes-from mydata busybox sh -c "cat /var/lib/mysql/hello"
hello
docker@alt:~$ exit
$ docker-machine restart alt
Starting VM...
$ docker-machine ssh alt
docker@alt:~$ docker run --rm --volumes-from mydata busybox sh -c "cat /var/lib/mysql/hello"
cat: can't open '/var/lib/mysql/hello': No such file or directory
This definitely should work:
Can you elaborate more on the steps to reproduce your problem?
boot2docker has a read-only filesystem (will get wiped on reboot) with the exception of:
/var/lib/docker
/var/lib/boot2docker/profile
where the daemon flags can be tweaked)I don't use boot2docker, but if /data gets wiped on reboot, that's where your volume is being stored (
docker run -v /data:/var/lib/mysql
), so it will be lost.What you're doing is also combining two different patterns for handling volume persistence. In order to get persistence, containers can mount volumes from a specified location on the host system (which is presumed to be persistent), or they can be associated with a data container, and mounted with
--volumes-from
. It sounds like the host filesystem approach is not appropriate for boot2docker, and you should use the data volume pattern (only).Presumably you should be creating your data container with
-v /var/lib/mysql
, rather than-v /data:/var/lib/mysql
.Note that I am using docker for mac beta which is using the xhyve vm.
The contents of /var/lib/boot2docker will be persisted between machine restarts. So if you want certain files to be available on your vm put them in this directory.
If you want them to be accessible in a different location for running docker containers then you can add the following to /var/lib/boot2docker/profile:
If you want to add other configuration to system files that will persist between vm restarts such as extra values in your hosts file then you can add a command such as the one below to /var/lib/boot2docker/profile:
Hope it helps