Linux

Docker containers report 'no space left on device' after systemd tmpfiles cleaned /var/lib/docker metadata despite free disk space

Environment

Environment

Ubuntu 22.04 host, Docker Engine 20.10, /var/lib/docker on ext4 partition with ample free space (df -h shows 60% used), systemd-tmpfiles configured via /etc/tmpfiles.d/clean.conf to remove old files under /var/tmp and /var/lib/docker/tmp older than 7 days; systemd-tmpfiles --clean runs via daily timer

Symptoms

Symptoms

Multiple containers start failing file writes with EROFS/ENOSPC 'no space left on device' while host shows significant free space; restarting docker daemon temporarily allows new containers but errors return after tmpfiles cleanup runs

Observations

Observations

docker info reports overlay2 driver and many lowerdir/upperdir entries. Running df -i shows inode exhaustion under /var/lib/docker despite overall free blocks. After manually removing orphaned tmpfiles and docker system prune, containers can write again. journalctl shows systemd-tmpfiles removing files under /var/lib/docker/tmp and occasionally removing metadata files used by overlay driver

Already attempted

Already attempted

Restarted docker daemon, ran docker system prune -a --volumes, modified tmpfiles config to exclude /var/lib/docker/tmp (but change applied after next scheduled run), temporarily moved tmpfiles cleanup cron to a different time (issue still reproduced when original cleanup executed)

Question

Question

Did systemd tmpfiles removal of Docker temporary files corrupt overlay metadata or exhaust inodes, and how should tmpfiles be safely configured to avoid breaking Docker storage?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
selmascript Answer
user
Posted 4w ago • 0 confirmations

Stop letting systemd-tmpfiles touch Docker's storage. Remove or change the tmpfiles.d rule that removes /var/lib/docker/tmp and instead run Docker-aware cleanup (docker system prune -a --volumes or a docker-gc job) on a safe schedule. To recover now: stop Docker (systemctl stop docker), check inode usage (df -i), run docker system prune after restart, and avoid running tmpfiles against /var/lib/docker in future. Verify by re-running the tmpfiles job manually—if no ENOSPC appears and containers can write, the config change succeeded. Roll back by restoring the original tmpfiles file if you need to re-enable broader cleanup.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

systemd-tmpfiles removed files under /var/lib/docker (tmp or metadata), causing overlayfs metadata inconsistencies or orphaned inodes leading to inode exhaustion 85%
High volume of container temp files previously created exhausted inode table; tmpfiles reduced free inodes by touching filesystem layout causing failure to reclaim inodes quickly 50%
Underlying filesystem corruption triggered by concurrent deletes and container overlay operations leading to transient ENOSPC until docker restart 30%

Summary

Tmpfiles cleanup targeting /var/lib/docker/tmp can remove files Docker expects at runtime or leave overlay metadata in inconsistent state; removing files inside Docker's storage directories risks orphaning references and creating many small metadata objects (or leaving dentry/inode gaps) causing inode exhaustion. The immediate cause of 'no space left' despite block space is inode exhaustion or overlay metadata inconsistency after pruning internal tmp dirs. Best fixes: exclude Docker data dirs from tmpfiles, schedule Docker-knowledgeable cleanup via docker system prune or use Docker GC tools, and recover by stopping Docker, repairing metadata, then restarting.

Suggested Fixes

Diagnostic step 1
Immediate recovery: stop Docker (systemctl stop docker), run fsck if suspected corruption (only on unmounted partition), restart Docker and run docker system prune -a --volumes to reclaim space safely.
Diagnostic step 2
Preventive: remove any tmpfiles.d rules that target /var/lib/docker or /var/lib/docker/tmp; create an explicit exclusion for Docker directories.
Diagnostic step 3
Use Docker-native cleanup: schedule docker system prune or use docker-gc instead of systemd-tmpfiles to remove docker artifacts.

Continue troubleshooting

Matched from the title, description and tags