DevOpsil
DockerHigh

Fix: Docker No Space Left on Device

Docker build fails with 'no space left on device'

!Symptoms

  • Docker build fails with 'no space left on device'
  • Docker pull fails with 'write /var/lib/docker/... no space left on device'
  • Containers fail to start with disk space errors
  • df -h shows /var/lib/docker partition is full

?Root Causes

  • Accumulated unused images, containers, and volumes consuming disk space
  • Docker build cache growing unbounded
  • Application writing large log files inside the container
  • Many dangling images from repeated builds without cleanup
  • Small root partition with Docker using the default /var/lib/docker path

#Diagnosis Steps

  1. 1Check disk usage: `df -h /var/lib/docker`
  2. 2Check Docker disk usage breakdown: `docker system df`
  3. 3List large images: `docker images --format '{{.Size}}\t{{.Repository}}:{{.Tag}}' | sort -h`
  4. 4Find large volumes: `docker volume ls -q | xargs -I {} docker volume inspect {} --format '{{.Name}} {{.Mountpoint}}'`
  5. 5Check for large container logs: `du -sh /var/lib/docker/containers/*/`

>Fix

  1. 1Clean unused resources: `docker system prune -a --volumes` (removes all unused data)
  2. 2Remove dangling images only: `docker image prune`
  3. 3Remove stopped containers: `docker container prune`
  4. 4Remove unused volumes: `docker volume prune`
  5. 5Limit container log size in daemon.json: `{"log-opts": {"max-size": "10m", "max-file": "3"}}`

*Prevention

  • Set up automated Docker cleanup via cron: `docker system prune -f` daily
  • Configure log rotation in Docker daemon.json
  • Use multi-stage builds to reduce image sizes
  • Mount a larger separate disk for /var/lib/docker
  • Set up disk usage alerts at 80% threshold

Related Error Messages

no space left on devicewrite /var/lib/dockerfailed to register layer: Error processing tar fileENOSPC: no space left on devicethin pool has no free data space