Journeys · Docker · L1
docker build and the layer cache
Build once, build again, change one file, change it back. Watch which steps run.
✓ Validated on Docker Engine 29.9.3 · Run 1 · 2026-11-20Preview
The 30-second answer
BuildKit runs the Dockerfile's steps in order and keeps each result in its cache. On the next build, a step is reused if its instruction and its inputs match: CACHED. For COPY, the inputs are the files. Change a file and that COPY runs again, and so does every step after it, even if nothing they use changed. The image is a list of layers: the base image's, then one per step that wrote files.
Mental model
A baker with a shelf of half-finished cakes, labelled by recipe step and ingredients. If today's step and ingredients match a label, the baker takes the cake from the shelf instead of baking it.
Where the analogy breaks
A real baker could swap the icing and keep the cake underneath. BuildKit cannot: once one step misses, every later step is baked again. And the shelf never forgets on its own: change a file back and yesterday's cakes match again.
🔒 Free account
Sign up free to play this journey
A free account unlocks every scenario, journey and exam, and saves your progress. No payment, ever.