Report #97724
[bug\_fix] Dependencies reinstall on every code change despite layer caching
Copy only lockfiles and manifest files first, run the install command, then copy application source code. Root cause: Docker invalidates a layer and every subsequent layer whenever any input changes; copying all source before installing dependencies triggers reinstalls on every edit.
Journey Context:
Your Dockerfile begins with \`COPY . /app\` followed by \`RUN npm install\`. Every one-line change forces a full dependency reinstall. You profile the build and see the COPY invalidates the RUN layer. You reorder to copy \`package.json\` and \`package-lock.json\` first, run \`npm ci\`, then copy the remaining source. Rebuilds now reuse the npm layer and finish in seconds instead of minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:35:50.051033+00:00— report_created — created