Contents

Docker Volume Commands Tutorial: Create, List, Inspect, and Remove Volumes

docker volume manages volumes. For the concepts and usage, see Volumes and data persistence.

Subcommands

CommandDescriptionCommon options
docker volume create [name]Create a volume (a random name is generated if none is provided)--label key=value, -d driver, -o option
docker volume lsList volumes-f filter, -q names only, --format
docker volume inspect nameShow detailed information-f template
docker volume rm name...Remove volumes (volumes in use cannot be removed)-f
docker volume pruneRemove unused anonymous volumes-a include named volumes, -f skip confirmation, --filter

Filters for docker volume ls -f: dangling=true (not used by any container), name=partial-name, label=key=value, and driver=local.

Create, write, and read

$ docker volume create mydata
mydata

$ docker volume ls
DRIVER    VOLUME NAME
local     2bc47e5efc92fb9cbc751a0d25853c6c800d4e4806c256fb7d68fa9dff112fcd
local     6729482c30a3f652c14f542c6f341c811f087fc9626efcfdf00a49a5ae721e2c
local     78297657b68403b39f39940496ce3faf49e6257a11d5103d043077a36261236a
local     a23af26d1da49e018edecb6e29f9be3875fb02e8c50510a40fbb5cf49da94f81
local     mydata

$ docker volume inspect mydata
[
    {
        "CreatedAt": "2026-10-13T05:28:56Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/mydata/_data",
        "Name": "mydata",
        "Options": null,
        "Scope": "local"
    }
]

$ docker run --rm -v mydata:/data alpine:3.23 sh -c "echo saved > /data/a.txt"

$ docker run --rm -v mydata:/data alpine:3.23 cat /data/a.txt
saved
  • In ls, besides mydata, there are several long-named anonymous volumes left behind by earlier containers (for example, automatically created by a VOLUME declaration in the postgres image).
  • Mountpoint in inspect is the actual location of the data on the Docker host.
  • Two different containers mounted mydata one after the other, and the second read the file written by the first: the data is in the volume, independent of the container.

Find and clean up dangling volumes

$ docker run --rm -v /tmpdata alpine:3.23 true

$ docker volume ls -f dangling=true
DRIVER    VOLUME NAME
local     2bc47e5efc92fb9cbc751a0d25853c6c800d4e4806c256fb7d68fa9dff112fcd
local     6729482c30a3f652c14f542c6f341c811f087fc9626efcfdf00a49a5ae721e2c
local     78297657b68403b39f39940496ce3faf49e6257a11d5103d043077a36261236a
local     a23af26d1da49e018edecb6e29f9be3875fb02e8c50510a40fbb5cf49da94f81
local     mydata

$ docker volume prune -f
Deleted Volumes:
a23af26d1da49e018edecb6e29f9be3875fb02e8c50510a40fbb5cf49da94f81
6729482c30a3f652c14f542c6f341c811f087fc9626efcfdf00a49a5ae721e2c
78297657b68403b39f39940496ce3faf49e6257a11d5103d043077a36261236a
2bc47e5efc92fb9cbc751a0d25853c6c800d4e4806c256fb7d68fa9dff112fcd

Total reclaimed space: 348.9MB
  • -v /tmpdata specifies only a path inside the container, with no name, so Docker creates an anonymous volume. --rm also removes it when the container is removed.
  • dangling=true lists all volumes that no container is currently using, including the named volume mydata.
  • prune -f removed only the four anonymous volumes and reclaimed 348.9 MB; the named volume mydata was kept.

Labels

$ docker volume create --label env=dev tagged
tagged

$ docker volume ls -f label=env=dev
DRIVER    VOLUME NAME
local     tagged

$ docker volume rm mydata tagged
mydata
tagged

Add labels to volumes to make them easier to filter and clean up by project or environment, for example, with docker volume prune --filter label=env=dev.

Exercises

Exercise: Create a volume labeled project=demo, then use one command to delete all unused volumes with that label, including named volumes.

Answer
docker volume create --label project=demo demo_data
docker volume prune -a -f --filter label=project=demo

-a includes named volumes in the removal scope, and --filter limits removal to volumes with this label.

FAQ

Do I have to run docker volume create first?

No. docker run -v name:/path automatically creates a volume if it doesn't exist. Creating it first lets you add labels or driver options.

Will docker volume prune delete my database?

Since Docker 23, docker volume prune deletes only **anonymous volumes that aren't used by any container**. Named volumes are kept. docker volume prune -a deletes unused named volumes too; see [Freeing disk space](/docker/cleanup/) for a hands-on example.

How do I back up a volume?

Use a temporary container that mounts both the volume and a host directory, then package the data with tar. See [Volumes and data persistence](/docker/volumes/) for an example.

Updated October 14, 2026