Introduction Docker can consume all available disk space through accumulated logs, dangling images, unused volumes, and build cache. When the host disk is full, all containers stop working and new containers cannot start.

Symptoms - `df -h` shows /var/lib/docker at 100% or near full - Container fails to start: "no space left on device" - Docker daemon logs: "overlay2: error creating overlay mount" - Existing containers running but cannot write to volumes - `docker system df` shows massive unused space

Common Causes - Container logs growing unbounded (no log rotation) - Accumulated unused images from deployments - Dangling build cache from docker build - Anonymous volumes from docker-compose recreation - overlay2 storage driver inefficiency

Step-by-Step Fix 1. **Analyze Docker disk usage**: ```bash docker system df docker system df -v ```

  1. 1.Clean up unused resources:
  2. 2.```bash
  3. 3.# Remove stopped containers, unused networks, dangling images
  4. 4.docker system prune -a --volumes --force

# Remove only dangling images docker image prune -f

# Remove unused volumes docker volume prune -f ```

  1. 1.Configure container log rotation:
  2. 2.Create /etc/docker/daemon.json:
  3. 3.```json
  4. 4.{
  5. 5."log-driver": "json-file",
  6. 6."log-opts": {
  7. 7."max-size": "10m",
  8. 8."max-file": "3"
  9. 9.}
  10. 10.}
  11. 11.`
  12. 12.Then restart Docker: systemctl restart docker
  13. 13.Clean up old overlay2 layers:
  14. 14.```bash
  15. 15.# Check overlay2 size
  16. 16.du -sh /var/lib/docker/overlay2
  17. 17.# If abnormally large, prune and rebuild
  18. 18.docker system prune -af
  19. 19.`

Prevention - Always configure log rotation in daemon.json - Run `docker system prune` in CI/CD cleanup steps - Set up monitoring for /var/lib/docker disk usage - Use named volumes instead of anonymous volumes - Implement automated cleanup cron jobs - Consider using btrfs or zfs storage drivers for better space management