Docker: no space left on device

Free disk space consumed by Docker images, containers, and build cache when 'no space left on device' errors occur.

Docker produces "no space left on device" when the Docker storage directory (default: /var/lib/docker) fills the disk with images, stopped containers, dangling layers, and build cache.

What Causes This Error

Unused Docker images, stopped containers, and build cache accumulate over time. Each docker build creates cached layers. Each docker pull downloads image layers. Stopped containers retain their writable layer until explicitly removed.

How to Fix

  1. Remove all unused Docker resources in one command:
docker system prune -a --volumes

The -a flag removes all unused images (not just dangling ones). The --volumes flag removes unused volumes. Warning:This deletes all data in unnamed volumes.

  1. Check disk usage by Docker component:
docker system df
  1. Remove stopped containers only:
docker container prune
  1. Remove dangling images only:
docker image prune