Clean Up Docker: Free Disk Space Safely

Remove stopped containers, unused images, volumes and build cache with the prune commands.

Show commands

Docker quietly fills your disk with old images, stopped containers and build cache. The prune commands clean this up without shell tricks like docker rm $(docker ps -aq).

1. See what's using space

docker system df

Add -v for a breakdown per image, container and volume.

2. Clean up step by step

# Stopped containers
docker container prune

# Dangling images (untagged layers left over from builds)
docker image prune

# All images not used by any container – more aggressive
docker image prune -a

# Build cache (often the biggest item on build machines)
docker builder prune

# Unused volumes
docker volume prune

Note on volumes: since Docker Engine 23, docker volume prune only removes anonymous volumes. Add --all to include named volumes – and double-check first, because volumes contain data such as databases.

3. Everything at once

# Stopped containers, unused networks, dangling images, build cache
docker system prune

# Additionally: all unused images and anonymous volumes
docker system prune -a --volumes

Keep recent items

On CI runners or dev machines it's useful to only remove older data:

docker image prune -a --filter "until=168h"   # older than 7 days
docker builder prune --filter "until=24h"

Safety notes

  • All prune commands ask for confirmation. -f skips it – use that only in scripts you trust.
  • Removing images means they have to be pulled or built again next time.
  • Never prune volumes on a server without knowing what's in them.