volume
docker volume
Manages persistent named volumes for containers — create, list, inspect, remove, and prune. Named volumes survive container removal and are the recommended storage mechanism over bind mounts for stateful data.
docker volume COMMAND Common flags
| Flag | Purpose |
|---|---|
| -d, --driver | Volume driver (default local) |
| --name | Explicit volume name on create |
| -o, --opt | Driver-specific options (e.g., type=nfs) |
| -f, --force | Force removal without confirmation |
| --filter | Filter output on ls/prune (e.g., dangling=true) |
Examples
docker volume create pgdata Create a named volume
docker run -v pgdata:/var/lib/postgresql/data postgres:16 Mount the named volume into a container
docker volume inspect pgdata Show mountpoint and driver metadata
docker volume prune Remove all volumes not referenced by any container
Gotcha
docker rm -v only removes ANONYMOUS volumes — named volumes must be deleted explicitly. On Docker Desktop the volume mountpoint lives inside the VM, so browsing /var/lib/docker/volumes from the host won't work.
Related commands
docker run
Creates and starts a new container from a specified image in a single step. This is the primary command for launching workloads and supports extensive configuration for networking, storage, and process control.
docker rm
Removes one or more stopped containers from the host. Use -f to force-remove a running container.
docker compose
Manages multi-container applications defined in a compose.yaml file. This is the Compose V2 plugin invoked via 'docker compose' (space); the legacy hyphenated 'docker-compose' binary is deprecated.
docker inspect
Returns low-level JSON metadata about Docker objects — containers, images, networks, volumes, and more. Supports Go template formatting for extracting specific fields.
← All Docker commands · Docker vs Kubernetes · Docker vs VMs