Report #30124
[bug\_fix] Docker image rebuilds from scratch \(re-installing dependencies\) every time source code changes
Reorder the Dockerfile instructions to copy dependency manifests \(e.g., package.json, requirements.txt\) first, run the dependency installation step, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because dependencies are re-downloaded. They know Docker uses layer caching, so they are baffled why the cache is invalidated. They look at the Dockerfile and see COPY . . followed by RUN npm install. Because COPY . . brings in all source code, the layer checksum changes whenever any source file changes. This invalidates the cache for all subsequent layers, including the expensive RUN npm install step. The fix requires splitting the copy step: first copy only the dependency manifests, run the install step \(which gets cached as long as manifests don't change\), and then copy the remaining source code. This isolates the volatile source code changes from the stable dependency installation layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:57:04.677249+00:00— report_created — created