Reported symptoms
- Application logs errors about disk space.
- Container runs out of storage unexpectedly fast.
Evidence provided
$ docker exec CONTAINER df -h
Filesystem Size Used Avail Use% Mounted on
overlay 10G 10G 0 100% /
$ du -sh /var/lib/docker/overlay2/<id>/diff/
9.5G /var/lib/docker/overlay2/<id>/diff/
Resolution path
- Find the largest files in the writable layer.
find /var/lib/docker/overlay2/<id>/diff -size +100M -type f- Common culprits: log files, database files, downloaded artefacts.
- Truncate or remove the largest files.
truncate -s 0 /var/lib/docker/overlay2/<id>/diff/var/log/myapp.logrm /var/lib/docker/overlay2/<id>/diff/tmp/largefile- Configure log rotation.
- Update daemon.json:
- ```json
- {
- "log-driver": "json-file",
- "log-opts": { "max-size": "10m", "max-file": "3" }
- }
- ```
- Restart Docker:
systemctl restart docker. - Recreate the container.
docker compose up -d- Use a volume for persistent data.
- Mount a named volume for paths that need to persist beyond container lifecycle.
- Set tmpfs for ephemeral caches.
--tmpfs /tmp:rw,size=64m
Verification
- Writable layer size is bounded.
docker exec CONTAINER df -hshows free space.- Application resumes normal operation.
- No more "no space left on device" errors.
Prevention
- Configure log rotation at the daemon level.
- Mount volumes for any persistent data the application writes.
- Use tmpfs for caches and temporary files.
- Set per-container storage quotas (when supported by your storage driver).
- Monitor disk usage; alert at 80%.