Docker: Cleanup
6 Docker commands: Cleanup. Click a command to see what each part does.
Docker: CleanupIndex
- Whole sheet120
- Basics: images & containers11
- Volumes & networks4
- Find & inspect containers7
- Environment variables & container config12
- Software versions inside containers & images9
- Logs & shells5
- Run containers3
- Images4
- Cleanup6
- Docker Compose v27
- Container lifecycle & live changes10
- Builds, multi-platform & moving images11
- Volumes, networks & remote hosts in depth12
- Compose: more commands9
- Swarm mode10
Cleanup6
docker system dfHow much space Docker usesWhat each part does
docker system dfspace used by images, containers, volumes and build cache, plus how much is reclaimable
docker ps -q | xargs -r docker stopStop all running containersCautionWhat each part does
docker ps -qIDs of running containers|pipe them to xargsxargs -rpass them as arguments; -r: don't run if the list is emptydocker stopstop each one gracefully (SIGTERM, then SIGKILL after 10s)
docker ps -aq --filter status=exited | xargs -r docker rmRemove all exited containersCautionWhat each part does
-aqall containers, IDs only--filter status=exitedonly exited onesxargs -r docker rmremove them
Tip Same result: docker container prune
docker system prune -f --filter "until=24h"Remove unused data older than a dayCautionWhat each part does
docker system pruneremove stopped containers, unused networks, dangling images and build cache-f--force: no confirmation prompt--filter "until=24h"only things older than 24 hours
docker system prune -a --volumesRemove everything unused, including volumesDestructiveWhat each part does
-a--all: also every image not used by a container (not just dangling)--volumesalso unused volumes: this deletes data
docker builder prune -af --filter "until=24h"Remove build cache onlyCautionWhat each part does
docker builder pruneremove BuildKit build cache (image prune does not touch it)-aall cache, not only dangling-fno prompt--filter "until=24h"keep the last day of cache
Nothing matches.
My DevOps Playbook by Angelo John Calleja