Docker: no space left on device
Free disk space consumed by Docker images, containers, and build cache when 'no space left on device' errors occur.
Docker produces "no space left on device" when the Docker storage directory (default:
/var/lib/docker) fills the disk with images, stopped containers, dangling layers, and build cache.
What Causes This Error
Unused Docker images, stopped containers, and build cache accumulate over time. Each
docker build creates cached layers. Each
docker pull downloads image layers. Stopped containers retain their writable layer until explicitly removed.
How to Fix
- Remove all unused Docker resources in one command:
docker system prune -a --volumesThe
-a flag removes all unused images (not just dangling ones). The
--volumes flag removes unused volumes.
Warning:This deletes all data in unnamed volumes.
- Check disk usage by Docker component:
docker system df- Remove stopped containers only:
docker container prune- Remove dangling images only:
docker image prune