Skip to content

Cleaning up: rm, rmi and prune

Select an icon to see what it is.

Step 6 of 6

Prune with care

Pruning cannot be undone, and -a and --volumes remove much more. A stopped container you want to inspect later, or a volume holding data, is deleted just the same. Use filters such as --filter until=24h or a label to limit the damage, and be careful on shared or production hosts.

PrevNext

POST /v1.45/containers/prune?filters=...

{
"filters": {
"until": [
"24h"
]
"label": [
"demo=prune"
]
}
}

Try it yourself

Clean up with filters, so only the demo objects are removed.

$ docker system df
$ docker run --name tmp1 --label demo=prune alpine true
$ docker ps -a --filter label=demo=prune
$ docker container prune -f --filter label=demo=prune
$ docker network create --label demo=prune demo-net
$ docker network prune -f --filter label=demo=prune

Quiz

1. What is a dangling image?
2. What does docker system prune leave alone by default?
3. How can you make a prune safer?