✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.1.4.1 Stopped Container Removal

A focused guide to Stopped Container Removal, connecting core concepts with practical Docker and container operations.

Stopped container removal refers specifically to cleaning up containers that have already stopped but were never removed, an accumulation that happens easily over time during everyday development and testing, and that Docker provides dedicated tooling to address in bulk.

Identifying Accumulated Stopped Containers

Listing only stopped (exited) containers reveals how many have accumulated without being explicitly removed.

docker ps -a --filter "status=exited"

It's common for this list to grow substantially during active development, where containers are frequently started for quick tests and left stopped rather than immediately cleaned up.

Removing All Stopped Containers at Once

Rather than removing stopped containers individually, a single command can clean up every stopped container in one step.

docker container prune

This prompts for confirmation before proceeding, removing every container currently in a stopped state.

Automating Cleanup to Prevent Accumulation

Using --rm when creating containers known to be temporary prevents this accumulation from happening in the first place, rather than needing to periodically clean it up after the fact.

docker run --rm myapp:1.0 quick-test-command
Checking Reclaimed Disk Space

Confirming how much disk space cleanup actually reclaimed demonstrates the concrete benefit of regularly removing accumulated stopped containers.

docker system df
docker container prune
docker system df

Comparing the reported disk usage before and after pruning shows exactly how much space the accumulated stopped containers had been occupying.

Why Stopped Container Removal Matters

Accumulated stopped containers are an easy, common source of unnecessary disk usage during active development — periodically cleaning them up, or better, using --rm proactively for genuinely temporary containers, keeps the local development environment from gradually filling up with inert, forgotten containers.