Optimizing Dockerfile layer caching
WHAT IT TESTS: how layer caching invalidation works. OUTLINE: order instructions least-to-most volatile, copy dependency manifests and install before copying source, and understand any changed layer busts all later layers.
WHAT IT TESTS: whether you understand that each Dockerfile instruction is a cached layer and a change invalidates that layer and every one after it. ANSWER OUTLINE: place rarely-changing steps first, copy only dependency manifests then install so that layer stays cached, copy application source last, and use a dockerignore file. Mention BuildKit cache mounts for package caches. RED FLAG: doing COPY . . before installing dependencies, which forces a full reinstall whenever any source line changes.
Read the original → interview
- #docker
- #dockerfile
- #build-cache
- #performance
- #ci
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.