How to remove all docker volumes?

Edited on 2017: This answer was given on Apr 16 '16 and now is outdated, and correct only for docker version prior to 1.13 please use the answer from @VonC, now it is marked as correct

To delete unused volumes you can use the built-in docker volume rm command. The rm command also deletes any directory in /var/lib/docker/volumes that is not a volume, so make sure you didn't put anything in there you want to save:
Command to List volumes, little bit right than yours:

$ docker volume ls -qf dangling=true

Cleanup:

$ docker volume rm $(docker volume ls -qf dangling=true)

more details about ls here, about rm here


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)

To answer the question and borrowing from Marc, this works:

$ docker volume rm $(docker volume ls -qf dangling=true | xargs)

This is what I've found to be useful: https://github.com/chadoe/docker-cleanup-volumes

Shellscript to delete orphaned docker volumes in /var/lib/docker/volumes and /var/lib/docker/vfs/dir Docker version 1.4.1 up to 1.11.x

It basically does a cleanup of any orphaned/dangling volumes, but it includes a --dry-run but it makes note of some docker included commands as well (which are referenced in prev comment)

Note about Docker 1.9 and up

To delete orphaned volumes in Docker 1.9 and up you can also use the built-in docker volume commands instead of this docker-cleanup-volumes script. The built-in command also deletes any directory in /var/lib/docker/volumes that is not a volume so make sure you didn't put anything in there you want to save:

List:

$ docker volume ls -qf dangling=true

Cleanup:

$ docker volume rm $(docker volume ls -qf dangling=true)

Or, handling a no-op better but Linux specific:

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

Tags:

Docker