Cleanup & Prune

How to Clean Up Docker Disk Space (Prune Containers, Images & Volumes)

Reclaim gigabytes of hard drive space by removing stopped containers, unused networks, dangling images, and build caches.

Quick Docker Solution
Destructive (Data Deletion)Intermediate
docker system prune -a --volumes
When to use this scenario:Your local machine or CI/CD runner is running out of disk space due to accumulated build layers, dangling images, and stopped containers.

Step-by-Step Execution Guide

1Check Docker disk space usage
docker system df

Displays a breakdown of disk space consumed by Images, Containers, Local Volumes, and Build Cache.

2Safe cleanup (stopped containers, unused networks, dangling images)
docker system prune

Deletes stopped containers, networks not used by at least one container, and dangling images without tags.

3Deep cleanup including all unused images
docker system prune -a

-a removes all unreferenced images, not just dangling ones.

4Maximum cleanup including volumes (Destructive)
docker system prune -a --volumes -f

WARNING: Permanently deletes all stopped containers, unused images, build caches, and unattached volumes (-f bypasses prompt).

Critical Docker Pitfalls & Precautions

  • β€’Using "--volumes" will permanently erase database data stored in Docker volumes not currently attached to a running container!
  • β€’Make sure required containers are actively running before executing system prune.
Frequently Asked Questions

Clean Up Docker Disk Space - Frequently Asked Questions

Common questions about container isolation, signal handling, and runtime behavior.

Run "docker builder prune -a" to remove multi-stage build cache without touching your images or volumes.