0
0
DockerDebug / FixBeginner · 4 min read

How to Fix 'No Space Left on Device' Error in Docker

The no space left on device error in Docker happens when disk space or inodes are full. Fix it by removing unused Docker objects with docker system prune or cleaning specific resources like images, containers, and volumes.
🔍

Why This Happens

This error occurs because Docker uses disk space for images, containers, volumes, and build cache. Over time, unused or stopped containers and dangling images accumulate, filling up the disk or inode limits. When Docker tries to create or write data but finds no free space, it throws the no space left on device error.

bash
docker run busybox echo hello
Output
docker: Error response from daemon: write /var/lib/docker/overlay2/...: no space left on device.
🔧

The Fix

Free up space by removing unused Docker data. The command docker system prune deletes stopped containers, unused networks, dangling images, and build cache. Add -a to remove all unused images, not just dangling ones. This clears space and fixes the error.

bash
docker system prune -a -f
Output
Deleted Containers: abc123... Deleted Images: xyz789... Total reclaimed space: 1.2GB
🛡️

Prevention

To avoid this error in the future, regularly clean unused Docker resources. Use automated scripts or scheduled jobs to run docker system prune. Monitor disk usage with docker system df and set up alerts. Also, consider increasing disk size or moving Docker storage to a larger volume.

⚠️

Related Errors

  • Docker build fails: Often caused by full disk during image build. Fix by cleaning build cache with docker builder prune.
  • Cannot start container: May happen if Docker storage is full. Clean volumes with docker volume prune.

Key Takeaways

Run docker system prune -a -f to free up disk space by removing unused Docker data.
Regularly monitor Docker disk usage with docker system df to prevent space issues.
Automate cleanup tasks to avoid accumulation of unused containers, images, and volumes.
Increase disk size or relocate Docker storage if space is consistently insufficient.
Use specific prune commands like docker builder prune and docker volume prune for targeted cleanup.