LinuxCommandLibrary

docker-volume

Manage persistent data volumes with Docker

TLDR

Create a volume

$ docker volume create [volume_name]
copy

Create a volume with a specific label
$ docker volume create --label [label] [volume_name]
copy

Create a tmpfs volume a size of 100 MiB and an uid of 1000
$ docker volume create [[-o|--opt]] [type]=[tmpfs] [[-o|--opt]] [device]=[tmpfs] [[-o|--opt]] [o]=[size=100m,uid=1000] [volume_name]
copy

List all volumes
$ docker volume ls
copy

Remove a volume
$ docker volume rm [volume_name]
copy

Display information about a volume
$ docker volume inspect [volume_name]
copy

Remove all unused local volumes
$ docker volume prune
copy

Display help for a subcommand
$ docker volume [subcommand] --help
copy

SYNOPSIS

docker volume create|inspect|ls|prune|rm [OPTIONS] [VOLUME...]

PARAMETERS

create
    Create a new volume

inspect
    Display detailed information on volumes

ls
    List volumes

prune
    Remove unused local volumes

rm
    Remove one or more volumes

DESCRIPTION

The docker volume command manages named data volumes used by Docker containers for persistent storage. Volumes outlive containers, enabling data persistence across container recreations. Unlike bind mounts from host paths, volumes are fully managed by Docker, stored in /var/lib/docker/volumes/ by default on Linux hosts.

Key functionalities include creating volumes with custom drivers (e.g., local, nfs), listing volumes with filters, inspecting detailed metadata like mountpoints and driver status, pruning unused volumes to reclaim space, and removing specific volumes. Volumes support labels for metadata and driver-specific options.

Essential for stateful apps like databases (e.g., MySQL, PostgreSQL). Integrates with Docker Compose and Swarm for orchestrated deployments. Anonymous volumes (created via docker run -v) are listed but managed differently. Always stop dependent containers before rm/prune to avoid errors.

CAVEATS

Cannot remove volumes in use by running containers.
Prune skips volumes referenced by containers.
Default driver is 'local'; requires root for host mounts.

CREATE OPTIONS

--driver string (default: local)
-l, --label []
-o, --opt []

LS OPTIONS

-f, --filter [] (name, driver, label, dangling)
-q, --quiet

INSPECT OPTIONS

-f, --format string
-v, --verbose

PRUNE OPTIONS

-f, --force
--filter [] (label, until)

RM OPTIONS

-f, --force

HISTORY

Introduced in Docker 1.9.0 (Nov 2015) for improved volume management over bind mounts. Enhanced in later versions with drivers, labels, and prune (1.13+).

SEE ALSO

Copied to clipboard