brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker volume prune skips named volumes unless you add -a

Docker
~/tips/tip-docker-volume-prune-all

docker volume prune -a

Know which unused volumes a prune removes, and when it removes your data too.

Since Docker 23, docker volume prune removes only unused anonymous volumes, the ones with long random names. Named volumes survive unless you ask for them with -a.

docker volume prune
docker volume prune -a

The first is fairly safe: anonymous volumes are usually left over from docker run without --rm or from images that declare a VOLUME. The help text says it plainly for the second: remove all unused volumes, not just anonymous ones.

That matters a lot. Unused means no container refers to it right now, stopped containers included. So if you ran docker compose down on a project to update it, its database volume is unused at that moment, and prune -a deletes it, with no undo.

Before any prune, I’d list what would go:

docker volume ls --filter dangling=true

A label filter makes the cleanup safer. Give throwaway volumes a label such as temp and prune only those with docker volume prune --filter label=temp.

Older Docker versions pruned named volumes too without any flag, so an old script or how-to can behave differently from what you expect. Check docker volume prune --help on the machine itself.

Further reading: docker volume prune, Docker Engine 23.0 release notes

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link