How to fix Error response from daemon: no space left on device in Docker

DockerBEGINNERHIGHUpdated Dec 6, 2025ยท 228 views

This error occurs when Docker cannot create or start containers because the host filesystem has run out of disk space. The fix involves cleaning up unused Docker resources with prune commands or expanding storage capacity.

Quick fix

Fixes Error response from daemon: no space left on device

docker system df
  1. Check Docker disk usage
  2. Run docker system prune to clean up
  3. Clean up Docker volumes
  4. Clear the build cache
docker โ€” error
docker system df
Error response from daemon: no space left on device

What this error means

The "Error response from daemon: no space left on device" error indicates that the Docker daemon cannot complete an operation due to insufficient disk space on the host system. This typically happens when creating containers, pulling images, or writing data to volumes. Docker stores all its data in the /var/lib/docker directory on Linux (or within a virtual disk on Docker Desktop for Mac/Windows). This includes: - Container layers and writable container filesystems - Downloaded and built images - Named and anonymous volumes - Build cache from docker build operations - Container logs When the filesystem hosting this directory becomes full, the Docker daemon fails with this error. The daemon response format ("Error response from daemon:") indicates this is a server-side error originating from the Docker Engine rather than the client. Over time, Docker environments accumulate unused resources. Stopped containers, dangling images, orphaned volumes, and build cache can consume tens of gigabytes. Without regular cleanup, even large disks eventually fill up.

Typical symptoms

  • Container creation fails with 'no space left on device' error
  • Docker run commands exit immediately with daemon error
  • Docker pull fails when downloading image layers
  • Docker build fails during COPY or RUN instructions
  • 'docker system df' shows high usage across images, containers, or volumes
  • Host system shows low or zero available disk space with 'df -h'
  • Multiple stopped containers listed in 'docker ps -a'
  • Many dangling images visible with 'docker images -f dangling=true'

Common causes

  1. Accumulated Docker build cache from frequent image builds
  2. Stopped containers consuming disk space (container writable layers persist)
  3. Dangling images from previous builds not automatically removed
  4. Docker volumes containing old or unused data
  5. Large container log files that have grown without rotation
  6. Small partition allocated for /var/lib/docker
  7. Pulling many large images without cleaning up old ones
  8. CI/CD pipelines not cleaning up after builds

How to fix "Error response from daemon: no space left on device"

1Check Docker disk usage

Analyze how Docker is consuming disk space:

bash
docker system df

This shows space used by images, containers, local volumes, and build cache. Example output:

bash
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          25        5         8.5GB     6.2GB (72%)
Containers      10        2         2.1GB     1.8GB (85%)
Local Volumes   15        3         4.3GB     3.9GB (90%)
Build Cache     0         0         5.1GB     5.1GB

For a detailed breakdown of each item:

bash
docker system df -v

Also check host disk space:

bash
df -h /var/lib/docker
2Run docker system prune to clean up

The quickest fix is Docker's built-in prune command that removes unused resources:

bash
docker system prune

This removes:
- All stopped containers
- All networks not used by at least one container
- All dangling images (untagged images)
- All dangling build cache

For a more aggressive cleanup that removes ALL unused images (not just dangling):

bash
docker system prune -a

Add -f to skip confirmation:

bash
docker system prune -af

Note: The -a flag will remove all images not associated with a running container. You'll need to re-pull them later.

3Clean up Docker volumes

By default, docker system prune does NOT remove volumes to prevent data loss. Remove unused volumes separately:

bash
docker volume prune

Or include volumes in the system prune:

bash
docker system prune -a --volumes

To see what volumes exist before deleting:

bash
docker volume ls

Warning: Volumes may contain important data like database files. Back up critical volumes before pruning.

4Clear the build cache

Docker BuildKit cache can grow significantly with frequent builds. Clear it with:

bash
docker builder prune

To remove ALL build cache (not just unused entries):

bash
docker builder prune -a

This is especially useful in development environments with many iterative builds.

5Remove specific unused resources

For targeted cleanup when you need finer control:

Remove stopped containers only:

bash
docker container prune

Remove dangling images only:

bash
docker image prune

Remove ALL unused images:

bash
docker image prune -a

List images sorted by size to identify large ones:

bash
docker images --format "{{.Repository}}:{{.Tag}} {{.Size}}" | sort -k2 -h

Remove specific images:

bash
docker rmi <image_id_or_name>

Remove unused networks:

bash
docker network prune
6Configure container log rotation

Container logs can grow unbounded and consume significant space. Configure log rotation in /etc/docker/daemon.json:

json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Then restart Docker:

bash
sudo systemctl restart docker

To immediately truncate logs for a running container:

bash
# Find container ID
docker ps

# Truncate log (requires sudo)
sudo truncate -s 0 /var/lib/docker/containers/<container_id>/<container_id>-json.log

For new containers, you can also specify log options at runtime:

bash
docker run --log-opt max-size=10m --log-opt max-file=3 <image>
7Verify cleanup and retry

Confirm disk space has been recovered:

bash
docker system df
df -h /var/lib/docker

Then retry your original command:

bash
docker run <your_image>
# or
docker-compose up
# or
docker build -t <tag> .

The operation should now complete successfully.

Advanced notes

Docker Desktop (Mac/Windows): Docker Desktop uses a virtual disk that can be resized. Go to Settings > Resources > Advanced > Disk image size (or "Virtual disk limit" in newer versions) to increase capacity. The disk file is located at:
- macOS: ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
- Windows: %LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx

Moving Docker's data directory: If /var/lib/docker is on a small partition, relocate it by editing /etc/docker/daemon.json:

json
{
  "data-root": "/mnt/larger-disk/docker"
}

Then migrate:

bash
sudo systemctl stop docker
sudo rsync -aP /var/lib/docker/ /mnt/larger-disk/docker/
sudo systemctl start docker

Automated cleanup in CI/CD: Add cleanup steps to prevent pipeline failures:

yaml
# GitHub Actions example
- name: Docker cleanup
  run: docker system prune -af --volumes
yaml
# GitLab CI example
after_script:
  - docker system prune -af --volumes

Kubernetes/container orchestration: If running Docker inside Kubernetes pods or as part of a container orchestration platform, consider:
- Using ephemeral runners that start fresh
- Mounting the Docker socket from the host (be aware of security implications)
- Using kaniko or buildah for rootless, daemonless builds

Prevention strategies:
- Schedule regular prune jobs: 0 3 * * * /usr/bin/docker system prune -af
- Use --rm flag for temporary containers: docker run --rm ...
- Tag images specifically instead of relying on latest to avoid version accumulation
- Monitor /var/lib/docker usage with alerting (e.g., Prometheus node_exporter)
- Set up automatic image cleanup policies in your container registry

Inode exhaustion: Rarely, you may have disk space but no inodes. Check with df -ih. Docker's many layer files can exhaust inodes on some filesystems. Consider using XFS or increasing inode ratio when formatting.

Frequently asked questions

What does "Error response from daemon: no space left on device" mean?
The "Error response from daemon: no space left on device" error indicates that the Docker daemon cannot complete an operation due to insufficient disk space on the host system. This typically happens when creating containers, pulling images, or writing data to volumes. Docker stores all its data in the /var/lib/docker directory on Linux (or within a virtual disk on Docker Desktop for Mac/Windows).
How do I fix "Error response from daemon: no space left on device"?
This error occurs when Docker cannot create or start containers because the host filesystem has run out of disk space. The fix involves cleaning up unused Docker resources with prune commands or expanding storage capacity.
What causes "Error response from daemon: no space left on device"?
Accumulated Docker build cache from frequent image builds Stopped containers consuming disk space (container writable layers persist) Dangling images from previous builds not automatically removed
Is the "Error response from daemon: 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