advancedScenario-Based & System Design Questions

A `docker build` that used to take 30 seconds now takes 8 minutes after a teammate's recent Dockerfile change, with no obvious new heavy dependency added.

Most likely cause: an instruction earlier in the Dockerfile was reordered or modified in a way that broke cache reuse for everything after it — for example, moving a `COPY . .` (full source) above the dependency-installation step, which now invalidates the dependency cache on every single source change. Diagnose by reviewing the diff of the Dockerfile specifically for instruction-order changes, and fix by restoring the least-to-most-frequently-changing ordering.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to A service works correctly when run with `docker run` directly but behaves differently (wrong config, missing env vars) when started via `docker compose up`.← Back to all Docker questions