Why does docker-machine clear data on restart?
This definitely should work:
$ docker-machine ssh default
docker@default:~$ docker run -v /data --name mydata busybox true
docker@default:~$ docker run --volumes-from mydata busybox sh -c "echo hello >/data/hello"
docker@default:~$ docker run --volumes-from mydata busybox cat /data/hello
hello
docker@default:~$ exit
$ docker-machine restart default
Starting VM...
$ docker-machine ssh default
docker@default:~$ docker run --volumes-from mydata busybox cat /data/hello
hello
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:
- Containers and their data (volumes) -- this is what you read about
/var/lib/docker
- Docker images
- Docker configuration (e.g.
/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
.