Report #11492
[bug\_fix] Docker image rebuilds dependency installation layer \(e.g., \`npm install\`, \`pip install\`\) on every code change, taking minutes instead of seconds.
Copy only dependency manifests \(e.g., \`package.json\`, \`requirements.txt\`\) and run the install step \*before\* copying the rest of the source code \(\`COPY . .\`\).
Journey Context:
A developer sets up a Dockerfile for a Node.js app. They put \`COPY . .\` followed by \`RUN npm install\`. Every time they change a single line of source code and rebuild, the \`npm install\` step runs from scratch, downloading hundreds of megabytes. They assume Docker caching is broken. After reading about Docker layer caching, they understand that if \*any\* file in the \`COPY . .\` context changes, the cache for that layer and all subsequent layers is invalidated. By splitting the copy into \`COPY package.json package-lock.json ./\` -> \`RUN npm install\` -> \`COPY . .\`, the expensive dependency installation layer is only invalidated when the lockfile changes, while code changes only invalidate the final \`COPY . .\` layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:24:42.122321+00:00— report_created — created