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 into the 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.

Common commands

TaskCommandDescription
Create volumedocker volume create <name>Create a new named volume.
List volumesdocker volume lsShow all volumes on the host.
Inspect volumedocker volume inspect <name>Show volume metadata and mount point.
Remove volumedocker volume rm <name>Delete a volume (must be unused).
Prune volumesdocker volume pruneRemove all unused volumes.
Bind mountdocker run -v $(pwd):/app imgMount 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:16
Bind mount for live code editing
docker run --rm -it -v "$(pwd)":/app -w /app node:20 npm run dev

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 reclaim disk space.

Related cheatsheets


Last reviewed: 2026-06-15
Join our Discord Server