docker volume Command Reference
Manage named volumes.
docker volume groups the volume subcommands: create, ls, inspect, rm, and prune. Named volumes persist data outside a container lifecycle and are the recommended way to share or cache data between containers in a pipeline.
Common subcommands
docker volume create NAME- create a named volumedocker volume ls- list volumes (-q for names only)docker volume inspect NAME- show volume metadata as JSONdocker volume rm NAME- remove a volumedocker volume prune -f- remove all unused volumes
Example
shell
docker volume create pgdata
docker run -d --name db -v pgdata:/var/lib/postgresql/data postgres:16
docker volume prune -fIn CI
Use a named volume to persist a database between steps within a job, or to share a cache directory between containers. docker volume prune -f reclaims unused volumes on a persistent runner; a volume in use by any container is skipped.
Key takeaways
- Named volumes outlive containers and are the way to share or persist data.
- docker volume prune -f reclaims unused volumes on long-lived runners.
- A volume bound to any container is not pruned.
Related guides
docker run Command ReferenceReference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting…
docker system prune Command ReferenceReference for docker system prune in CI: reclaim disk by removing stopped containers, unused networks, dangli…
docker compose down Command ReferenceReference for docker compose down in CI: stop and remove containers, networks, and with -v the volumes, to te…