Persist data with Docker volumes

docker

Updated August 29, 2026

A Docker volume stores data outside a container's writable layer and can be reused when the container is replaced:

docker volume create app-data
docker run --rm -v app-data:/var/lib/app image:tag

Named volumes are managed by Docker and are useful for databases or other persistent application data. A bind mount maps a specific host path and is often better for source code during development:

docker run --rm -v "$PWD:/workspace" -w /workspace image:tag

Inspect mounts with docker inspect and list volumes with docker volume ls. Removing a container does not normally remove a named volume; docker volume rm does, so verify the name and backups first. Compose volumes declared at the top level are also persistent resources.

Volumes are not backups. Test a restore, protect database files from concurrent access, and avoid mounting the Docker socket or broad host directories into an untrusted container.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author