How to fix write /var/lib/docker/tmp/...: no space left on device in Docker
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.
Quick fix
Fixes write /var/lib/docker/tmp/...: no space left on device
docker system df- Check Docker disk usage
- Prune unused Docker resources
- Clear Docker build cache specifically
- Remove specific unused images
docker system dfwrite /var/lib/docker/tmp/...: no space left on device
What this error means
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.
Typical symptoms
- Docker build commands fail with "no space left on device" errors
- docker pull fails when trying to download new images
- Container creation fails even though df shows available space
- Build fails at COPY or ADD instructions in Dockerfile
- CI/CD pipelines fail during Docker image build steps
- docker system df shows high disk usage for build cache or images
Common causes
- Accumulated Docker build cache from previous builds consuming disk space
- Many unused or dangling Docker images taking up storage
- Stopped containers that were never removed still occupying space
- Unused Docker volumes persisting on disk
- The partition containing /var/lib/docker has limited capacity
- Inode exhaustion on the filesystem (rare but possible)
How to fix "write /var/lib/docker/tmp/...: no space left on device"
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.
Advanced notes
### 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
Frequently asked questions
- What does "write /var/lib/docker/tmp/...: no space left on device" mean?
- 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.
- How do I fix "write /var/lib/docker/tmp/...: no space left on device"?
- 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.
- What causes "write /var/lib/docker/tmp/...: no space left on device"?
- Accumulated Docker build cache from previous builds consuming disk space Many unused or dangling Docker images taking up storage Stopped containers that were never removed still occupying space
- Is the "write /var/lib/docker/tmp/...: no space left on device" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐Docker Docs: pruning(Official Docs)
- ๐Docker Docs: prune(Official Docs)
- ๐Docker Docs: prune(Official Docs)
- ๐ฌStack Overflow: docker error no space left on device(Stack Overflow)
- ๐
- ๐
- ๐