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