Docker Error: “No space left on device” — How to Clean Up Docker Disk Usage

If you’ve run into the dreaded error:

no space left on device

while working with Docker, it means your Docker environment has consumed too much disk space. This can happen over time as containers, images, volumes, and other resources accumulate on your system. Fortunately, Docker provides built-in commands to help you clean up and reclaim that space.


🧠 Why Does Docker Consume So Much Space?

Docker stores:

  • Images: Pulled or built locally
  • Containers: Including stopped ones
  • Volumes: Persistent storage for containers
  • Networks: Custom or bridge networks
  • Build cache: Intermediate layers and metadata

Over time, unused or “dangling” resources accumulate, leading to excessive disk usage.


🧹 How to Clean Up Docker Resources

🔸 1. Remove Stopped Containers

Stopped containers still take up space.

docker container prune

This will remove all stopped containers. Add -f to skip confirmation:

docker container prune -f

🔸 2. Remove Unused Images

Unused or old images can consume gigabytes.

docker image prune -a

Use -a to remove all images not associated with any container.


🔸 3. Remove Unused Volumes

Volumes are often overlooked but can be large, especially for database containers.

docker volume prune

🔸 4. Remove Build Cache

Docker build caches intermediate layers to speed up builds.

docker builder prune --all

🔸 5. Run a Full Cleanup

To remove everything not currently used:

docker system prune -a --volumes

This cleans:

  • Stopped containers
  • Unused images
  • Unused volumes
  • Build cache
  • Networks not in use

⚠️ Warning: This is irreversible. Make sure you don’t need the unused data.


📊 Check Docker Disk Usage

Before or after cleanup, check what’s using space:

docker system df

Sample output:

TYPE                TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images              10        3         5GB       3.5GB
Containers          6         1         1.2GB     1GB
Local Volumes       5         0         2.5GB     2.5GB
Build Cache         -         -         1.8GB     1.8GB

🛠️ Optional: Automate Cleanup

Create a shell alias or cron job to run regular cleanups:

alias docker-clean="docker system prune -a --volumes -f"

📍 Conclusion

The “no space left on device” error is Docker’s way of saying it’s time to tidy up. Regular pruning and monitoring will keep your system clean and Docker running smoothly.

Reclaim your disk space and keep coding with confidence.

Sharing Is Caring:

Leave a Comment