How to fix write /var/lib/docker/tmp/...: no space left on device in Docker

DockerBEGINNERHIGHUpdated Dec 6, 2025ยท 255 views

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
  1. Check Docker disk usage
  2. Prune unused Docker resources
  3. Clear Docker build cache specifically
  4. Remove specific unused images
docker โ€” error
docker system df
write /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

  1. Accumulated Docker build cache from previous builds consuming disk space
  2. Many unused or dangling Docker images taking up storage
  3. Stopped containers that were never removed still occupying space
  4. Unused Docker volumes persisting on disk
  5. The partition containing /var/lib/docker has limited capacity
  6. Inode exhaustion on the filesystem (rare but possible)

How to fix "write /var/lib/docker/tmp/...: no space left on device"

1Check Docker disk usage

First, examine how Docker is using disk space to understand what needs cleanup:

bash
docker system df

This shows a breakdown of disk usage by images, containers, volumes, and build cache. Look for the component using the most space.

2Prune unused Docker resources

Remove all unused Docker objects (stopped containers, unused networks, dangling images, and build cache):

bash
docker system prune -f

For a more aggressive cleanup that also removes unused images (not just dangling ones) and volumes:

bash
docker system prune -af --volumes

Warning: The --volumes flag will delete unused volumes. Make sure you don't have important data in Docker volumes before running this.

3Clear Docker build cache specifically

If build cache is the main culprit (common with frequent builds), clear it directly:

bash
docker builder prune -af

The -a flag removes all build cache, not just dangling cache. Without it, some cache may not be cleared.

If using BuildKit with buildx:

bash
docker buildx prune -af
4Remove specific unused images

List all images and their sizes:

bash
docker images -a

Remove specific images you no longer need:

bash
docker rmi image_name:tag

Remove all dangling images (untagged images):

bash
docker image prune -f
5Check for inode exhaustion

Sometimes the disk has space but is out of inodes. Check inode usage:

bash
df -ih

If 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.

6Verify available disk space

After cleanup, verify you have sufficient space:

bash
df -h /var/lib/docker

Check Docker disk usage again:

bash
docker system df

You should see reduced usage and can retry your build.

7Move Docker data directory (if partition is too small)

If your root partition is too small, move Docker's data to a larger partition:

1. Stop Docker:

bash
sudo systemctl stop docker

2. Create or edit /etc/docker/daemon.json:

json
{
  "data-root": "/path/to/new/docker-data"
}

3. Copy existing data (optional, if you want to preserve images):

bash
sudo rsync -aP /var/lib/docker/ /path/to/new/docker-data/

4. Restart Docker:

bash
sudo systemctl start docker
8Increase disk size in Docker Desktop

If 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:

bash
docker buildx prune --max-used-space 10GB

This 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