Explain a build where `COPY` always misses the cache even though code did not change.
IntermediateScenarioMulti-stage builds, cache, tags and registries
Answer
Situation read → Cache key for COPY is a checksum of file contents and metadata (mode), not mtime.
What I'd do →
- Look for generated files in context (
build/,*.log,.DS_Store, version stamp files) and add them to.dockerignore. - Check that a script rewrites file permissions on checkout.
- Run
docker buildx build --progress=plain .and compare which step is notCACHED.
Why → One changed byte in the copied set invalidates this layer and all after it.
Interview tip → Copy narrowly (COPY src/ src/) rather than the whole context.
More on Multi-stage builds, cache, tags and registries
Show a multi-stage Dockerfile for a Java Spring Boot app and explain what you gain.BeginnerCI rebuilds from scratch every run and takes 12 minutes. How do you bring it down?IntermediateYou tag every build `myapp:latest`. A rollback is requested. What happens?BeginnerHow do you promote an image from dev to prod registry without rebuilding?IntermediateDisk on the build server keeps filling up with images.BeginnerWhen do you use `--no-cache` and when is it a smell?Beginner