Skip to main content

Docker Volume Cheatsheet — Persistent Data & Storage

Containers are ephemeral by design — data is lost when they stop. Volumes and bind mounts let you persist data, share files between containers, and manage storage independently of the container lifecycle.

Updated: 2026-07-15·23 commands

Quick Reference

ScenarioCommand
List volumesdocker volume ls
Create a volumedocker volume create my-data
Inspect a volumedocker volume inspect my-data
Remove a volumedocker volume rm my-data
Prune unused volumesdocker volume prune
Run container with volumedocker run -v my-data:/app/data nginx
Run with bind mountdocker run -v $(pwd):/app nginx
Run with read-only volumedocker run -v my-data:/app/data:ro nginx

Volume vs Bind Mount

FeatureVolumeBind Mount
Managed by Docker✅ Yes❌ No
Location/var/lib/docker/volumes/Any host path
Backup/RestoreEasy (docker CLI)Manual
Cross-host portable✅ Yes❌ Path-dependent
Development live-reload✅ Yes (syncs host edits)
Recommended forProduction data, databasesDevelopment, config files

Core Commands

### Managing Volumes

``bash # Create a named volume docker volume create postgres-data

# List volumes docker volume ls

# Inspect volume details (mountpoint, driver, labels) docker volume inspect postgres-data

# Remove a specific volume (container must not be using it) docker volume rm postgres-data

# Remove all unused volumes docker volume prune `

### Using Volumes with Containers

`bash # Named volume — Docker manages the storage location docker run -d --name db -v postgres-data:/var/lib/postgresql/data postgres:16

# Anonymous volume — Docker generates a random name docker run -d -v /var/lib/postgresql/data postgres:16

# Read-only volume (container cannot write) docker run -d -v config-data:/etc/nginx/conf.d:ro nginx

# Multiple volumes docker run -d \ -v app-data:/app/data \ -v config-data:/etc/nginx/conf.d:ro \ nginx `

### Bind Mounts

`bash # Mount current directory to /app inside container docker run -v $(pwd):/app node:20 npm run dev

# Mount with read-only docker run -v $(pwd):/app:ro node:20 npm test

# Mount specific directory (absolute path) docker run -v /home/user/project:/app node:20 npm start `

### Backup & Restore

`bash # Backup a volume to a tar file docker run --rm \ -v my-volume:/source \ -v $(pwd):/backup \ alpine tar czf /backup/my-volume-backup.tar.gz -C /source .

# Restore a volume from a tar file docker run --rm \ -v my-volume:/target \ -v $(pwd):/backup \ alpine tar xzf /backup/my-volume-backup.tar.gz -C /target ``

Volume(23)

CommandLevel
docker volume create
Create a new volume
Basic
docker volume ls
List all volumes
Basic
docker volume inspect
Inspect volume details
Basic
docker volume rm
Remove one or more volumes
Basic
docker volume prune
Remove all unused volumes
Expert
docker run -v
Run a container with a volume mount
Intermediate
docker run --mount
Run a container with advanced mount options
Expert
docker volume --help
Display docker volume help information
Basic
docker volume create --driver
Create a volume with a specific driver
Intermediate
docker volume create --label
Create a volume with labels
Intermediate
docker volume create -o type=btrfs
Create a volume with a specific filesystem type
Expert
docker volume ls -q
Show only volume names
Basic
docker volume ls --filter
List volumes filtered by criteria
Intermediate
docker volume inspect --format
Custom format volume inspection output
Expert
docker volume prune -f
Force remove all unused volumes without prompt
Basic
docker volume prune --filter
Prune unused volumes with filter
Expert
docker run -v (bind mount)
Run a container with a host directory bind mount
Intermediate
docker run -v $(pwd):/app
Mount current directory into container (hot-reload for dev)
Basic
docker run --mount type=bind
Use --mount syntax for bind mounting
Intermediate
docker run --mount type=tmpfs
Run a container with a tmpfs mount (in-memory)
Expert
docker run --mount type=volume,readonly
Run a container with a read-only volume mount
Intermediate
docker run --mount type=volume,volume-driver
Run a container with a third-party volume driver
Expert
docker run --mount type=volume,volume-opt
Run a container with volume driver options
Expert

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-15.