How to keep data in Docker with volumes
Updated 10/23/2026
When you delete a container, the data inside it is gone. Docker volumes store data outside the container so it survives recreation.
1. Create a volume
docker volume create app_data
2. Attach it to a container
docker run -d --name db -v app_data:/var/lib/mysql mysql:8
Even if you delete the db container and recreate it, the data stays in the app_data volume.
3. Bind mounts vs volumes
A bind mount maps a directory from the server straight into the container, useful for config files:
docker run -v /etc/app:/config nginx
A volume is managed by Docker and is recommended for application data (databases).
4. Useful commands
docker volume ls
docker volume inspect app_data
docker volume rm app_data
Backup
Volumes should be backed up regularly. See How to back up Docker containers to send them to a Backup Box.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to run your own private Docker registry
Host your own Docker images on a private server, without depending on external services.
Updated 10/23/2026Docker & containersHow to read logs and debug Docker containers
When a container fails to start or stops on its own, the logs tell you why. Here is how to read and debug them.
Updated 10/23/2026Docker & containersHow to free up disk space used by Docker
Images, stopped containers and orphaned volumes can fill your disk. Here is how to clean them up safely.
Updated 10/23/2026