docker / cli

The Docker CLI
Apache License 2.0
4.94k stars 1.93k forks source link

volumes wont be deleted since update to docker 23 #4028

Closed Emporea closed 1 year ago

Emporea commented 1 year ago

Since the update to docker 23 unused volumes will not be deleted anymore with docker volume prune nor docker system prune --volumes.

The answer is always Total reclaimed space: 0B. When I delete the volumes manually I even get these warning when running docker-compose.yml Error response from daemon: open /var/lib/docker/volumes/docker_volume1/_data: no such file or directory

Whats happening?

robcresswell commented 10 months ago

@havardox

docker system prune --all --volumes --force && docker volume prune --all --force

I have that aliased as

alias dprune='docker system prune --all --volumes --force && docker volume prune --all --force'
kuchaguangjie commented 8 months ago

With Docker version 25.0.4, build 1a576c5. In my test docker volume prune won't even remove unused anonymous volumes. I've to add -a option to remove it.

boneitis commented 8 months ago

It's been a while since I had looked at this. My best interpretation to the best of my memory was that there were a few pieces that weren't all rolled out at the same time, which resulted in dangling volumes for me. Something like, if a volume was created pre-23, then they would resist pruning attempts on 23 due to missing some metadata label that you'd expect to see from docker inspect. Or maybe it was volume creation during 23, and pruning attempts post-23. Something along those lines.

All I remember was that once 23 was far enough back in the rear-view mirror and my production environments were eventually able to create everything (images, containers, artifacts, whathaveyou) afresh from Docker versions no earlier than 24, everything worked with the right single pruning command scripted, without having to accommodate edge cases in versioning or manually intervene with getting the incantation right with the correct flags.

Probably the easiest way to roll with it if you're still stuck in the mire of pre-23 post-23 mixed deployments is to peg your Docker Engine API version on your machines to an older value.

cpuguy83 commented 8 months ago

@boneitis You are absolutely correct.

mattwelke commented 5 months ago

The info from @boneitis was helpful. We had a bunch of volumes that weren't being removed with docker volume prune. We had just upgrades Docker a few days earlier, so upgrading Docker may have been related. These volumes were just used by build steps so we didn't care about them. We listed all of them and deleted them one by one, resolving our disk space issue.