Home Explore Blog CI



docker

3rd chunk of `content/manuals/build/cache/_index.md`
278ac517f51d36f7d59a820749828d147fb38e2f5b0411760000000100000412


Whenever a layer changes, that layer will need to be re-built. For example,
suppose you make a change to your program in the `main.c` file. After this
change, the `COPY` command will have to run again in order for those changes to
appear in the image. In other words, Docker will invalidate the cache for this
layer.

If a layer changes, all other layers that come after it are also affected. When
the layer with the `COPY` command gets invalidated, all layers that follow will
need to run again, too:



And that's the Docker build cache in a nutshell. Once a layer changes, then all
downstream layers need to be rebuilt as well. Even if they wouldn't build
anything differently, they still need to re-run.

## Other resources

For more information on using cache to do efficient builds, see:

- [Cache invalidation](invalidation.md)
- [Optimize build cache](optimization.md)
- [Garbage collection](garbage-collection.md)
- [Cache storage backends](./backends/_index.md)

Title: Docker Build Cache and Resources
Summary
The Docker build cache rebuilds all downstream layers when a layer changes, even if the downstream layers wouldn't build differently. The section also lists resources for further reading on cache invalidation, build cache optimization, garbage collection, and cache storage backends.