Need to double-check if this was by design, but docker rm -v (remove container including volumes attached to it) only removes anonymous volumes, but not named ones. However, the flag description does not mention this;
docker container rm --help
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
-f, --force Force the removal of a running container (uses SIGKILL)
-l, --link Remove the specified link
-v, --volumes Remove the volumes associated with the container
Steps to verify the current behavior:
docker run -d --name mycontainer1 -v /anonymous -v namedvol1:/namedvol nginx:alpine
docker run -d --name mycontainer2 -v /anonymous -v namedvol2:/namedvol nginx:alpine
docker volume ls
DRIVER VOLUME NAME
local 547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local 402827d64bced57d80125e52606d6b394c651c138cb829587798b041357523c2
local namedvol1
local namedvol2
Removing mycontainer1 keeps all volumes associated with the container:
docker rm -f mycontainer1
docker volume ls
DRIVER VOLUME NAME
local 547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local 402827d64bced57d80125e52606d6b394c651c138cb829587798b041357523c2
local namedvol1
local namedvol2
Whereas using the -v option removes the anonymous volume, but keeps the named volume:
docker rm -fv mycontainer2
docker volume ls
DRIVER VOLUME NAME
local 547d032c5571241ec33b6064dcaef1116c646b8a7e590a18bc56da9a2a22ddab
local namedvol1
local namedvol2
Need to double-check if this was by design, but
docker rm -v(remove container including volumes attached to it) only removes anonymous volumes, but not named ones. However, the flag description does not mention this;Steps to verify the current behavior:
Removing
mycontainer1keeps all volumes associated with the container:Whereas using the
-voption removes the anonymous volume, but keeps the named volume: