Interview Prep/Docker/Multi-stage builds, cache, tags and registries

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 →

  1. Look for generated files in context (build/, *.log, .DS_Store, version stamp files) and add them to .dockerignore.
  2. Check that a script rewrites file permissions on checkout.
  3. Run docker buildx build --progress=plain . and compare which step is not CACHED.

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.

All Docker questions Roadmap: Docker & containers

More on Multi-stage builds, cache, tags and registries