Docker volumes are not automatically removed when a container is stopped. To remove associated volumes when you stop a container:
docker rm -v <container id or name>
If the -v
flag is not specified, the volume remains on-disk as a 'dangling volume'. To delete all dangling volumes:
docker volume rm $(docker volume ls -qf dangling=true)
The docker volume ls -qf dangling=true
filter will return a list of docker volumes names, including untagged ones, that are not attached to a container.
Alternatively, you can use xargs
:
docker volume ls -f dangling=true -q | xargs --no-run-if-empty docker volume rm