Docker 24.x multi-stage builds eating disk space—any tips?
Hey all, I'm noticing my build cache is bloating up fast when running multi-stage builds with Docker 24.0.7. Each build seems to leave behind intermediate layers that aren't getting cleaned properly.
I've tried docker system prune -a but it's getting tedious. Should I be using --squash or is there a better approach? Also considering buildkit instead but not sure if it helps with this.
Anyone dealt with this? What's your workflow for keeping build artifacts under control on production runners?
Edited at 25 Mar 2026, 23:15
BuildKit actually helps a lot here—it's smarter about layer caching and cleanup. Enable it with DOCKER_BUILDKIT=1 and you'll see better performance. But for immediate relief, set a build cache policy: docker builder prune --filter type=build clears only build cache without nuking everything. Also, if you're not already, use .dockerignore aggressively to avoid bloating layers with unnecessary files. --squash works but defeats some caching benefits—not ideal for CI/CD. What's your current build frequency looking like?
Thanks for the tip! Yeah, I'll enable BuildKit and see if that helps with the cache management. Good point about it being smarter with layers—was hoping that'd be the case. I'll report back once I test it out.