Report #26584
[bug\_fix] Docker layer cache invalidated on every build causing slow dependency installation
Reorder the Dockerfile instructions to copy the dependency manifest files \(e.g., \`package.json\`, \`requirements.txt\`\) and run the installation command BEFORE copying the rest of the application source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because it reinstalls npm/pip packages from scratch. They assume the CI system is broken or not caching images properly. After digging into Docker's layer caching mechanism, they realize their Dockerfile starts with \`COPY . .\` followed by \`RUN npm install\`. Because \`COPY . .\` includes all source code, any minor change to a source file changes the layer's checksum, invalidating the cache for \`COPY . .\` and all subsequent layers including \`RUN npm install\`. The fix works because dependency manifests rarely change, so the \`RUN npm install\` layer stays cached even when application source code changes, drastically reducing build times.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:01:11.911395+00:00— report_created — created