CloudLinux.ro
Docker & containers

How to keep data in Docker with volumes

Updated 7/20/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 pricing

Related tutorials