This error occurs when Docker runs out of disk space during image builds. The fix typically involves cleaning up unused Docker resources, pruning build cache, or increasing available storage.
The "no space left on device" error during Docker builds indicates that the filesystem where Docker stores its data has run out of available space. Docker uses the `/var/lib/docker` directory by default to store images, containers, volumes, build cache, and temporary files. When building an image, Docker writes intermediate layers and files to `/var/lib/docker/tmp`. If this partition is full, the build process cannot continue and fails with this error. This commonly happens on systems with limited disk space, CI/CD runners with constrained storage, or development machines where Docker artifacts have accumulated over time. The error can also occur when you have technically available disk space but have run out of inodes (file system metadata entries). This is less common but worth checking if standard cleanup does not resolve the issue.
First, examine how Docker is using disk space to understand what needs cleanup:
docker system dfThis shows a breakdown of disk usage by images, containers, volumes, and build cache. Look for the component using the most space.
Remove all unused Docker objects (stopped containers, unused networks, dangling images, and build cache):
docker system prune -fFor a more aggressive cleanup that also removes unused images (not just dangling ones) and volumes:
docker system prune -af --volumesWarning: The --volumes flag will delete unused volumes. Make sure you don't have important data in Docker volumes before running this.
If build cache is the main culprit (common with frequent builds), clear it directly:
docker builder prune -afThe -a flag removes all build cache, not just dangling cache. Without it, some cache may not be cleared.
If using BuildKit with buildx:
docker buildx prune -afList all images and their sizes:
docker images -aRemove specific images you no longer need:
docker rmi image_name:tagRemove all dangling images (untagged images):
docker image prune -fSometimes the disk has space but is out of inodes. Check inode usage:
df -ihIf the IUse% is at 100% for the partition containing /var/lib/docker, you need to delete files or directories to free inodes. Running the Docker prune commands from previous steps should help.
After cleanup, verify you have sufficient space:
df -h /var/lib/dockerCheck Docker disk usage again:
docker system dfYou should see reduced usage and can retry your build.
If your root partition is too small, move Docker's data to a larger partition:
1. Stop Docker:
sudo systemctl stop docker2. Create or edit /etc/docker/daemon.json:
{
"data-root": "/path/to/new/docker-data"
}3. Copy existing data (optional, if you want to preserve images):
sudo rsync -aP /var/lib/docker/ /path/to/new/docker-data/4. Restart Docker:
sudo systemctl start dockerIf using Docker Desktop on Windows or macOS, increase the allocated disk space:
1. Open Docker Desktop
2. Go to Settings (gear icon)
3. Navigate to Resources > Advanced
4. Increase the Disk image size slider
5. Click Apply & Restart
This allows Docker to use more disk space from your host machine.
### Preventing Future Issues
To avoid running out of space again:
- Use .dockerignore: Exclude unnecessary files from build context to reduce image size and build cache usage
- Use multi-stage builds: Separate build-time dependencies from runtime to create smaller final images
- Choose slim base images: Use alpine or slim variants when possible
- Set up automated cleanup: Add docker system prune -f to a weekly cron job or CI/CD cleanup step
- Monitor disk usage: Set up alerts when /var/lib/docker exceeds a threshold
### Build Cache Management
You can limit build cache size with BuildKit:
docker buildx prune --max-used-space 10GBThis keeps the most recently used cache while staying under the limit.
### CI/CD Considerations
In CI/CD environments, consider:
- Using ephemeral runners that start fresh each build
- Running docker system prune -af at the start or end of pipelines
- Using remote caching instead of local build cache
unable to configure the Docker daemon with file /etc/docker/daemon.json
How to fix 'unable to configure the Docker daemon with file daemon.json' in Docker
docker: Error response from daemon: OCI runtime create failed: container_linux.go: starting container process caused: exec: "/docker-entrypoint.sh": stat /docker-entrypoint.sh: no such file or directory
How to fix 'exec: entrypoint.sh: no such file or directory' in Docker
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker