Report #26993
[bug\_fix] Docker build cache invalidated on every code change, even for dependency installation
Split the COPY instruction: copy only dependency manifests \(e.g., package.json, requirements.txt\) first, run the dependency installation, and then COPY the rest of the source code.
Journey Context:
A developer notices their CI builds take 10 minutes every time they change a single line of code. They assume Docker caching is broken. They check BuildKit settings and try adding \`--no-cache\` flags, making it worse. The root cause is a monolithic \`COPY . .\` instruction placed immediately before \`RUN npm install\`. In Docker, if any file changes in the context, the \`COPY . .\` layer cache is invalidated, which invalidates the cache for all subsequent layers, including the expensive dependency installation step. By separating the copy into \`COPY package.json package-lock.json ./\` first, the dependency installation layer is only rebuilt when the lockfile actually changes, drastically speeding up builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:42:18.420643+00:00— report_created — created