docker volume Explained

What docker volume does, with an example.

Published November 9, 2026

Docker volumes are managed storage that persists data beyond a container's life, ideal for databases and uploads.

How it works

Volumes live in Docker's storage area and survive docker rm. Bind mounts map a host folder instead.

Back up volumes by running a temporary container that archives them.

Try it

docker volume create pgdata
docker run -d -v pgdata:/var/lib/postgresql/data postgres:16
docker volume ls
local pgdata

Practical examples

Create and use

docker volume create pgdata
docker run -v pgdata:/data alpine ls /data

Bind mount for development

docker run -v $(pwd):/app -w /app node:20 npm test

Backup

docker run --rm -v pgdata:/data -v $(pwd):/backup alpine tar czf /backup/pg.tgz -C /data .

Remove unused

docker volume prune

Common mistakes

  • Storing data in the container layer and losing it.
  • Bind mount permission problems.
  • Pruning volumes with important data.

Key takeaways

  • Docker volumes are managed storage that persists data beyond a container's life, ideal for databases and uploads.
  • Run docker <command> --help for all options.
  • Clean up unused resources regularly.

FAQ

Volume vs bind mount?

Volumes are managed by Docker; bind mounts use a host path.

Where can I see all options?

Run the command with --help.

More General articles