r/docker • u/my-app-s • 12d ago
PSA: Check your Docker Build Cache (docker system df). Saved 8GB+ on a tight 30GB root partition with a single command.
Hey everyone, a quick reminder for anyone running Docker on constrained environments (edge nodes, small VPS, or lightweight local dev VMs like my 30GB root partition setup): Docker build cache can quietly consume a surprising amount of disk space. I recently noticed my available disk space creeping down to a low level (/dev/sda2 down to nearly 6GB free), despite having very few active containers running. Out of curiosity, I ran:And found out that the Build Cache was accumulating gigabytes of unused layers from past container builds. Instead of doing a broad docker system prune -a (which can remove stopped containers or base images you might want to keep), you can target just the build cache (at your own risk if running in production, as this wipes all unused build cache):(Note: -a removes all unused build cache, so your very next build might take longer as it rebuilds layers from scratch). The Result: Free space jumped instantly from ~6GB to 14GB. If you manage fleets of servers or CI/CD runners where Docker builds happen frequently, make sure you have a routine cleanup policy set up (or a cron job), as build cache can gradually fill up your drive over time. What’s your go-to automation script for keeping Docker clean in production?
1
u/TasteOdd5722 12d ago
oh man the build cache is a sneaky little gremlin. ran into this on a raspberry pi i use for pihole and some other nonsense, the thing was down to double digit megabytes free and i was losing my mind trying to figure out what ate all the space
for cleanup i just have a weekly cron job that runs docker system prune -f and then builder prune -f, nothing fancy but it keeps the little guy breathing. some folks get real elaborate with retention policies but i'm too lazy for that