I'm really interested in using Docker but I'm having trouble understanding how to manage stateful applications, like databases.
1. You run the db and its files inside a container and regularly export a DB dump like so (example for postgres):
docker run --volumes-from db -v $(pwd):/backup ubuntu:trusty sh -c "cd /var/lib && tar zcvf /backup/backup.tgz postgresql"
(I don't recommend this)
2. You run the db inside a docker container and mount a volume for /var/lib/postgresql into docker. This I find is the best way. the db files remain on your host and you can easily maintain the DB (runtime) and files separately.
Adjust to whatever DB you're using.
$ docker run --name db-data -v /var/lib/db busybox true
$ docker run --name db-server --volumes-from db-data db-image
This way you can remove the db-server container and recreated it with the same command and it will reuse the volume. See also https://docs.docker.com/userguide/dockervolumes/#creating-an...