Report #75481
[bug\_fix] Docker build cache invalidated on every build, causing dependency installation to run from scratch every time
Reorder the Dockerfile instructions to copy dependency manifests \(package.json, requirements.txt\) first, run the dependency installation step, and then copy the rest of the application code.
Journey Context:
A developer complains that their Docker build takes 10 minutes in CI even when no dependencies have changed. Looking at the build logs, they see that the 'CACHED' label appears for early steps, but the 'npm install' or 'pip install' step always runs. They initially suspect BuildKit cache export issues in CI. However, examining the Dockerfile reveals COPY . . placed right after the FROM instruction, followed by RUN npm install. Because Docker builds images layer-by-layer and checks the context checksum, any change to any source file \(even a README\) invalidates the COPY layer and all subsequent layers. By splitting the copy into two steps—copying only the manifest files, running the install, and then copying the source—the expensive dependency installation layer remains cached as long as the manifest doesn't change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:17:35.624416+00:00— report_created — created