Persistence

Let’s make sure our volume is working. If it’s working properly, a brand new container will still serve the data we created because it will load it from the volume.

Volumes are often used by applications like Ghost, Grafana, or WordPress to persist data so that when a container is deleted and a new one is created, the state of the application isn’t lost. Containerized applications are typically thought of as ephemeral (temporary). If your application breaks just because you deleted and recreated a container, it’s not a very good containerization!

Testing Persistence

First, get your container ID and stop/remove the container:

docker ps
docker stop CONTAINER_ID
docker rm CONTAINER_ID

Now, start a new container from the same image and attach the same volume:

docker run -d -e NODE_ENV=development -e url=http://localhost:3001 -p 3001:2368 -v my-vol:/var/lib/ghost ghost

If you check your application now, your state (e.g., your blog posts) will still be there! The new container successfully read the state from the persistent volume.