Report #27377
[bug\_fix] Docker build invalidates the RUN npm install \(or pip install\) cache layer every time source code changes, forcing a full reinstall.
Reorder the Dockerfile instructions: copy only the package manager manifest files \(package.json, requirements.txt\) first, run the package install command, and then copy the rest of the source code \(\`COPY . .\`\).
Journey Context:
A developer notices their CI builds take 10 minutes every time they change a single line of application code. They assume Docker layer caching is broken or the CI runner is misconfigured. They try adding \`--no-cache\` locally to 'reset' things, but it makes it worse. They inspect the Dockerfile and see \`COPY . .\` followed by \`RUN npm install\`. Because \`COPY . .\` includes all source code, its computed cache key changes every time \*any\* source file changes. Since \`RUN npm install\` comes after the COPY step, its cache is automatically invalidated by Docker's layer ordering rules. The fix is to split the copy: \`COPY package.json package-lock.json ./\` then \`RUN npm install\`, then \`COPY . .\`. Now, the expensive install step only re-runs when the lockfile changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:20:54.812223+00:00— report_created — created