Quantify build time saved by Docker layer caching and layer ordering.
Docker invalidates every layer after the first change, so a modification near the top rebuilds almost everything. Putting dependency installation before source copying is what keeps the expensive layers cached. Copying source before installing dependencies is the single most common Dockerfile mistake and usually multiplies CI build time several times over.
Docker Build Cache
Layers rebuilt = total layers − first changed layer + 1; everything after a change is invalidated
Layers rebuilt = total layers − first changed layer + 1; everything after a change is invalidated Docker invalidates every layer after the first change, so a modification near the top rebuilds almost everything. Putting dependency installation before source copying is what keeps the expensive layers cached.
Copying source before installing dependencies is the single most common Dockerfile mistake and usually multiplies CI build time several times over.
This calculator takes 5 inputs: Layers in the Dockerfile, First layer that changes, Average layer build time, Builds per day, Cache availability. The pre-filled defaults are a realistic starting point — replace them with figures from your own environment for a result you can act on.