The Build That Took 14 Minutes (Then 47 Seconds)
Changing one line in requirements.txt shouldn't rebuild your entire Docker image. But that's exactly what happens when your Dockerfile ignores how layer caching actually works.
I measured this on a real CI pipeline: a Python ML project with PyTorch, transformers, and about 40 other dependencies. The naive Dockerfile took 14 minutes on every push. After restructuring the layers? 47 seconds for code-only changes. Same image, same dependencies, same result — just better cache utilization.
The Docker build cache is simple in theory: each instruction creates a layer, and Docker reuses layers when nothing has changed. But "nothing has changed" is where things get tricky. Change one file that's copied early, and everything downstream rebuilds. The order of your instructions matters more than most developers realize.
Why Cache Invalidation Breaks (The Actual Mechanism)
Continue reading the full article on TildAlice

Top comments (0)