docker-volume

docker volume prune not deleting unused volumes


My understanding is docker volume prune should delete volumes which are no longer associated with containers.

Locally I have

$ docker volume ls | head -n 2
DRIVER    VOLUME NAME
local     0d4cd922a4ed3e970726b1edb860c7dda3ae1e47f812585d9517d512ae70d5cf

I confirm it doesn't have an associated container via

$ docker ps -a --filter volume=0d4cd922a4ed3e970726b1edb860c7dda3ae1e47f812585d9517d512ae70d5cf
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

therefore I expect this volume to be deleted, but alas

$ docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

$ docker volume ls | head -n 2
DRIVER    VOLUME NAME
local     0d4cd922a4ed3e970726b1edb860c7dda3ae1e47f812585d9517d512ae70d5cf

what am I missing ?


Solution

  • This is probably the issue mentioned in the docker cli github repo here: https://github.com/docker/cli/issues/4028

    Apparently docker version 23 no longer deletes anonymous volumes (like your volume seems to be) when running docker volume prune. To get the original behavior you can use docker volume prune --filter all=1.