Docker: Persistence With a Data-only Container
If you've been experimenting with Docker, you've probably discovered that each time you restart a container the data is gone. This is because each container is built from an image, and the image has no knowledge of what has happened within the previous container. This is quite necessary because the image was built from a specific set of instructions, and the container needs to be the same every time it's built.
But persistent data is kind of necessary at times. This guide will show you how to create a very basic set up with an application container, a database container, and a persistent data container. With this set up you'll be able to tear down and rebuild your application and database containers as frequently as you'd like without losing data.
Note (11/24/15) Although this guide is still somewhat applicable, there is a better way of doing things. Docker has since fixed a lot of issues with docker-compose and docker-machine. You can expect an updated version of this guide soon, but for now you might find this guide on docker compose somewhat useful. Even if you're not using Django, there is a section on persistent data.