Skip to content

Why data in a volume survives docker rm

Select an icon to see what it is.

Step 6 of 6

Prune removes unused volumes

docker volume prune sends POST /volumes/prune. In recent Docker versions it removes only anonymous volumes that no container uses. Named volumes are removed only with --all, so check what is unused before you run it.

$ docker volume prune
PrevNext

POST /v1.45/volumes/prune

no filter: anonymous unused volumes only
filters all=true: named unused volumes too

Try it yourself

Write to a volume and to the container layer, remove the container, and look again.

$ docker run -d --name tester -v appdata:/data alpine sleep 1000
$ docker exec tester sh -c 'echo hi > /data/a.txt; echo hi > /tmp/b.txt'
$ docker rm -f tester
$ docker volume ls
$ docker run --rm -v appdata:/data alpine ls /data
$ docker volume rm appdata

Quiz

1. Which file is gone after docker rm?
2. How do you delete a named volume?
3. What does a new container mounting the same volume see?