How to fix failed to extract layer: write /: no space left on device in Docker

DockerBEGINNERHIGHUpdated Dec 6, 2025ยท 276 views

This error occurs when Docker cannot extract image layers during a pull operation because the disk where Docker stores its data has run out of space. The solution involves cleaning up unused Docker resources and ensuring sufficient disk space.

Quick fix

Fixes failed to extract layer: write /: no space left on device

docker system df
  1. Check Docker disk usage
  2. Remove unused images
  3. Clean up stopped containers
  4. Clear build cache
docker โ€” error
docker system df
failed to extract layer: write /: no space left on device

What this error means

The "failed to extract layer: write /: no space left on device" error occurs when Docker is pulling an image from a registry and cannot extract one of the downloaded layers to disk. Docker images consist of multiple layers that are downloaded compressed and then extracted to the local filesystem. When Docker attempts to write the extracted layer data to /var/lib/docker (or Docker Desktop's virtual disk on Mac/Windows), the operation fails because no free space remains. This is distinct from general disk space errors because it specifically happens during the layer extraction phase of an image pull. Docker requires space for both the compressed download and the uncompressed extraction. A 500MB compressed layer might expand to 2GB when extracted, so even if you have enough space for the download, the extraction can still fail.

Typical symptoms

  • docker pull fails partway through with 'no space left on device'
  • Layer extraction fails after successful download
  • Large images consistently fail while smaller images succeed
  • 'docker system df' shows high disk usage across images and build cache
  • Error appears during CI/CD pipeline image pulls
  • Docker Desktop shows full disk warning

Common causes

  1. Accumulated unused Docker images from previous pulls
  2. Build cache consuming significant disk space
  3. Stopped containers still holding disk space
  4. Unused volumes not cleaned up
  5. Docker data directory on a partition with limited space
  6. Large image requiring more extraction space than available
  7. Docker Desktop disk image size limit reached

How to fix "failed to extract layer: write /: no space left on device"

1Check Docker disk usage

Start by understanding how Docker is using disk space:

bash
docker system df

This displays disk usage by category (Images, Containers, Local Volumes, Build Cache). For detailed breakdown:

bash
docker system df -v

Also check system-level disk space:

bash
df -h /var/lib/docker

On Docker Desktop, check Settings > Resources to see the disk image size and usage.

2Remove unused images

Clear images that are not being used by any container:

bash
# Remove dangling images (untagged, unreferenced)
docker image prune

# Remove ALL unused images (not just dangling)
docker image prune -a

To see what will be removed first:

bash
docker images -f "dangling=true"
docker images

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

3Clean up stopped containers

Stopped containers consume disk space. Remove them:

bash
# View stopped containers
docker ps -a --filter "status=exited"

# Remove all stopped containers
docker container prune

This frees the writable layer space used by each stopped container.

4Clear build cache

Docker's build cache can grow substantially, especially with frequent builds:

bash
# Remove dangling build cache
docker builder prune

# Remove ALL build cache
docker builder prune -a

In CI/CD environments, the build cache is often the largest consumer of disk space.

5Run comprehensive cleanup

For a complete cleanup of all unused Docker resources:

bash
# Remove containers, networks, images, and build cache
docker system prune -a

# Include volumes in cleanup (use with caution)
docker system prune -a --volumes

Warning: The --volumes flag permanently deletes data in unused volumes. Only use this if you are certain no important data exists in Docker volumes.

6Verify space and retry pull

Confirm disk space has been freed:

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

Then retry the image pull:

bash
docker pull <image-name>

For large images, ensure you have at least 2-3x the compressed image size available for extraction overhead.

Advanced notes

Docker Desktop disk limits: On Mac and Windows, Docker Desktop uses a virtual disk with a configurable size limit. Go to Settings > Resources > Advanced > Disk image size to increase it. On Mac, the Docker.raw or Docker.qcow2 file in ~/Library/Containers/com.docker.docker/Data/vms/0/data stores all Docker data.

Moving Docker's data directory: If /var/lib/docker is on a small root partition, relocate Docker's storage:

bash
sudo systemctl stop docker
sudo mv /var/lib/docker /new/location/docker

Edit /etc/docker/daemon.json:

json
{
  "data-root": "/new/location/docker"
}

Then restart: sudo systemctl start docker

Checking inodes: Disk space exhaustion can also be caused by running out of inodes, not bytes:

bash
df -ih /var/lib/docker

If IUse% is high, you have an inode problem rather than a space problem.

Thin pool issues (devicemapper): On older RHEL/CentOS systems using devicemapper, the thin pool may be exhausted. Check with docker info and look for Data Space and Metadata Space. Consider migrating to the overlay2 storage driver.

CI/CD considerations: In CI pipelines, always run docker system prune -af at the start or end of jobs. Consider using --filter "until=24h" to only remove resources older than 24 hours.

Preventing recurrence:
- Schedule regular cleanup: 0 0 * * 0 docker system prune -af in cron
- Use specific image tags instead of :latest
- Run containers with --rm flag for automatic cleanup
- Monitor disk usage with alerts at 70% and 85% thresholds

Frequently asked questions

What does "failed to extract layer: write /: no space left on device" mean?
The "failed to extract layer: write /: no space left on device" error occurs when Docker is pulling an image from a registry and cannot extract one of the downloaded layers to disk. Docker images consist of multiple layers that are downloaded compressed and then extracted to the local filesystem. When Docker attempts to write the extracted layer data to /var/lib/docker (or Docker Desktop's virtual disk on Mac/Windows), the operation fails because no free space remains.
How do I fix "failed to extract layer: write /: no space left on device"?
This error occurs when Docker cannot extract image layers during a pull operation because the disk where Docker stores its data has run out of space. The solution involves cleaning up unused Docker resources and ensuring sufficient disk space.
What causes "failed to extract layer: write /: no space left on device"?
Accumulated unused Docker images from previous pulls Build cache consuming significant disk space Stopped containers still holding disk space
Is the "failed to extract layer: write /: 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