How do you delete unused Docker containers, images, and volumes?
Quick Answer
Use docker system prune to remove stopped containers, dangling images, unused networks, and build cache; add -a to also remove unused (not just dangling) images, and --volumes to include unused volumes.
Detailed Answer
On busy build hosts, unused layers and stopped containers eat disk fast, causing no space left on device failures. docker system prune -a --volumes reclaims the most, but be careful: -a removes any image not used by a running container, and --volumes can delete data, so run it deliberately (a scheduled prune with retention is common in CI).
Code Example
docker system prune -a --volumes # reclaim disk; careful, removes unused images + volumes
Interview Tip
Warn that -a --volumes can delete data/images you still want — schedule pruning with care on shared hosts.