Report #70213
[bug\_fix] Dependency installation layer cache invalidated on every source code change
Reorder the Dockerfile to copy only dependency manifests \(e.g., \`package.json\`, \`requirements.txt\`\) first, run the installation step, and then copy the rest of the source code.
Journey Context:
A developer notices their Docker builds take 10 minutes every time they change a single line of code. Their Dockerfile has \`COPY . /app\` followed by \`RUN npm install\`. They assume Docker caching is broken or try to use \`--no-cache\` to fix stale builds, not realizing they are causing the cache miss themselves. Docker layer caching works top-down: if a layer changes, all subsequent layers are rebuilt. Because \`COPY . /app\` includes all source code, any code change invalidates that layer, forcing the expensive \`RUN npm install\` layer to rebuild. Splitting the copy ensures the dependency installation layer only invalidates when the dependency manifest changes, preserving the cache for routine code edits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:26:07.691698+00:00— report_created — created