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.Clean up unused resources:
- 2.```bash
- 3.# Remove stopped containers, unused networks, dangling images
- 4.docker system prune -a --volumes --force
# Remove only dangling images docker image prune -f
# Remove unused volumes docker volume prune -f ```
- 1.Configure container log rotation:
- 2.Create /etc/docker/daemon.json:
- 3.```json
- 4.{
- 5."log-driver": "json-file",
- 6."log-opts": {
- 7."max-size": "10m",
- 8."max-file": "3"
- 9.}
- 10.}
- 11.
` - 12.Then restart Docker:
systemctl restart docker - 13.Clean up old overlay2 layers:
- 14.```bash
- 15.# Check overlay2 size
- 16.du -sh /var/lib/docker/overlay2
- 17.# If abnormally large, prune and rebuild
- 18.docker system prune -af
- 19.
`