Interview Prep/Docker/Dockerfile Instructions & Builds

How does the build cache work?

IntermediateConceptDockerfile Instructions & Builds
Answer

For each instruction the builder computes a cache key from the parent layer plus the instruction text; for COPY/ADD it also includes a checksum of the copied files. A match reuses the layer. When one layer misses, all later layers rebuild. RUN apt-get update is cached by its text, not by the state of the apt repos, so it can go stale.

All Docker questions Roadmap: Docker & containers

More on Dockerfile Instructions & Builds