Join our Discord Server

Docker Volumes Cheatsheet

← All cheatsheets

CoreBeginner

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 directly into a container.

Installation

Built into Docker Engine and Docker Desktop. No additional installation needed.

Quick start

docker volume create mydata

Create a named volume.

docker run -v mydata:/app/data myimage

Mount a named volume into a container.

docker volume ls

List all volumes.

docker volume rm mydata

Remove a named volume.

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 (dangling) volumes.
Mount in run docker run -v <vol>:/path img Attach a volume at container start.
Bind mount docker run -v $(pwd):/app img Mount a host directory into the container.
tmpfs mount docker run --tmpfs /tmp img Mount a temporary in-memory filesystem.

Real-world examples

Named volume for a database
docker volume create pgdata
docker run -d --name postgres -v pgdata:/var/lib/postgresql/data postgres:16

Bind mount for live code editing
docker run --rm -it -v "$(pwd)":/app -w /app node:20 npm run dev

Backup a volume to a tar file
docker run --rm -v mydata:/data -v $(pwd):/backup alpine \
  tar czf /backup/mydata-backup.tar.gz /data


Best 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 prune regularly to clean up dangling volumes and reclaim disk.
  • Use read-only bind mounts (:ro) when containers only need to read host files.

Related cheatsheets


Last reviewed: 2026-06-15

Join our Discord Server