← All cheatsheets
Docker Volumes Cheatsheet
Manage persistent data storage for containers with named volumes and bind mounts.
What it is
Docker volumes provide persistent storage for containers. Named volumes are managed by Docker and survive container restarts. Bind mounts link a host directory into the container.
Installation
Built into Docker Engine and Docker Desktop. No additional installation needed.
Quick start
Create a named volume.
Mount a named volume into a container.
List all volumes.
Common commands
| Task | Command | Description |
|---|---|---|
| Create volume | docker volume create <name> | Create a new named volume. |
| List volumes | docker volume ls | Show all volumes on the host. |
| Inspect volume | docker volume inspect <name> | Show volume metadata and mount point. |
| Remove volume | docker volume rm <name> | Delete a volume (must be unused). |
| Prune volumes | docker volume prune | Remove all unused volumes. |
| Bind mount | docker run -v $(pwd):/app img | Mount a host directory into the container. |
Real-world examples
Named volume for a database
docker volume create pgdata
docker run -d --name postgres -v pgdata:/var/lib/postgresql/data postgres:16Bind mount for live code editing
docker run --rm -it -v "$(pwd)":/app -w /app node:20 npm run devBest practices
- Use named volumes for databases and stateful services, not bind mounts.
- Never store persistent data inside a container — always use volumes.
- Use
docker volume pruneregularly to reclaim disk space.
Related cheatsheets
Last reviewed: 2026-06-15