docker volume prune not deleting unused volumes
Asked Answered
M

2

12

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 ?

Muskogee answered 18/2, 2023 at 13:39 Comment(1)
Mind expanding on the close vote ? This is most definitely programming/software dev relatedMuskogee
C
25

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.

Crater answered 1/3, 2023 at 13:7 Comment(3)
wow thanks so much. That thread was very helpfulMuskogee
docker volume prune -a , is the answer. As per the docs option -a "Remove all unused volumes, not just anonymous ones"Alex
Brilliant. Thanks a lot!Aureolin
L
-1

The following command also removes orphan the images and networks

docker system prune -f
Linskey answered 20/4 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.