✦ For everyone, free.

Practical knowledge for real and everyday life

Home

2.1.3.4 Volume API Routes

A focused guide to Volume API Routes, connecting core concepts with practical Docker and container operations.

Volume API routes are the set of HTTP endpoints, under the /volumes path, that the Docker daemon exposes for creating, listing, inspecting, and removing the persistent storage volumes that allow data to outlive an individual container.

Listing Volumes

A route returns every volume currently known to the daemon, regardless of whether it is currently attached to a running container.

curl --unix-socket /var/run/docker.sock http://localhost/volumes

This is the data source behind docker volume ls, listing volumes independent of any container's current state.

Creating a Volume

Creating a volume through the API specifies its name and, optionally, the storage driver to use, mirroring the same options available through the CLI.

curl --unix-socket /var/run/docker.sock -X POST http://localhost/volumes/create \
  -H "Content-Type: application/json" \
  -d '{"Name":"myapp-data"}'
Inspecting a Volume

A dedicated route returns details about a specific volume, including where its data actually resides on the host filesystem.

curl --unix-socket /var/run/docker.sock http://localhost/volumes/myapp-data

This corresponds to docker volume inspect, and is useful when diagnosing exactly where a volume's underlying data is stored on disk.

Removing a Volume

A volume can be removed through the API once no container references it, the same safeguard the CLI applies to prevent accidentally deleting data still in active use.

curl --unix-socket /var/run/docker.sock -X DELETE http://localhost/volumes/myapp-data
Pruning Unused Volumes

A separate route removes every volume not currently referenced by any container in a single operation, useful for reclaiming disk space consumed by volumes left behind after their containers were removed.

curl --unix-socket /var/run/docker.sock -X POST http://localhost/volumes/prune
Why These Routes Matter

Automated backup tooling, storage management dashboards, or cleanup scripts that need to manage volumes without manual CLI intervention rely directly on these routes, since they provide the only programmatic interface to volume state the daemon maintains.