Quiz Entry - updated: 2026.12.01
Which states can a container be in, and how do you clean up all containers, images and volumes at once?
Up (running), Stopped/Exited, plus Created and Paused; stop everything with docker container stop $(docker container ls -aq), then docker system prune --all --force --volumes.
A container must be stopped (exited) before it can be removed, unless you force it with docker container rm -f.
Stop all containers:
docker container stop $(docker container ls -aq)
docker container ls -aq lists the IDs (-q = quiet, IDs only) of all containers (-a, including stopped ones). The shell's $( … ) runs that first and passes the IDs as arguments to stop.
Remove everything unused:
docker system prune --all --force --volumes
| Flag | Effect |
|---|---|
| (default) | Removes stopped containers, unused networks, dangling images and the build cache |
--all |
Also removes every image not used by a container (with all containers stopped, that is all of them) |
--force |
Skips the confirmation prompt |
--volumes |
Also removes unused volumes, which deletes their data permanently |
On a lab machine this gives a clean slate. On a server, --volumes is how you lose a database.
Go deeper:
Docker Docs: Prune unused Docker objects — prune per object type and what each removes.
Docker Docs: docker system prune — the flags and their effects.