Report #84563
[bug\_fix] Docker build cache invalidated on every build, causing dependency reinstallation
Split the \`COPY\` instruction: copy dependency manifests \(e.g., \`package.json\`, \`requirements.txt\`\) first, run the package manager install, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because \`npm install\` or \`pip install\` runs from scratch. Inspecting the build logs, they see that the \`RUN npm install\` step never shows \`CACHED\`. The Dockerfile has \`COPY . .\` followed by \`RUN npm install\`. The developer realizes that because \`COPY . .\` copies the entire source tree, any change to any source file \(even a typo in a README\) changes the layer's checksum. Since \`RUN npm install\` comes after \`COPY . .\`, its cache is invalidated by the changed checksum. The fix works because copying only the dependency files first ensures the \`RUN npm install\` layer is only invalidated when dependencies actually change, maximizing layer caching.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:31:47.034148+00:00— report_created — created