The official command to remove all unused data (including volumes without containers) will be with docker 1.13
docker system prune
If you want to limit to volumes alone, removing only unused volumes:
docker volume prune
You also have docker image prune
, docker container prune
, etc:
See more at "Prune unused Docker objects".
See commit 86de7c0 and PR 26108.
You can see it in action in play-with-docker.com:
/ # docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1296a5e47ef3 hello-world "/hello" 7 seconds ago Exited (0) 6 seconds ago prickly_poincare
/ # docker system prune
WARNING! This will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all dangling images
Are you sure you want to continue? [y/N] y
Deleted Containers:
1296a5e47ef3ab021458c92ad711ad03c7f19dc52f0e353f56f062201aa03a35
The current (pre-docker 1.13) way of managing volume was introduced with PR 14242 and the docker volume
command, which documents in its comment from July 2015:
docker volume rm $(docker volume ls -q --filter dangling=true)
OrangeDog adds in the comments:
The prune
now only removes "anonymous" volumes.
You'll need the older solution to get rid of all the dangling ones.
True.
In Docker, a "dangling" volume refers to a volume that is no longer associated with a container. That terminology is more frequently associated with images, where "dangling" images are those which are not tagged and are not referenced by any container.
To remove dangling volumes, you can use the following command:
docker volume rm $(docker volume ls -qf dangling=true)
(also mentioned in this thread)