How to Fix 'No Space Left on Device' Error in Docker
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.
docker run busybox echo hello
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.
docker system prune -a -f
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
docker system prune -a -f to free up disk space by removing unused Docker data.docker system df to prevent space issues.docker builder prune and docker volume prune for targeted cleanup.