Report #31606
[bug\_fix] Changing any source file invalidates the Docker layer cache for dependency installation \(e.g., RUN npm install\), causing full reinstalls
Split the COPY instruction: first COPY only the dependency manifest files \(package.json, requirements.txt\), then RUN the dependency install, and finally COPY the rest of the source code.
Journey Context:
A developer notices CI builds take 10 minutes every time, even for a 1-line code change. They check the Docker build logs and see RUN pip install -r requirements.txt running from scratch. They trace it back to the preceding COPY . . instruction. Because COPY . . copies all source code, its cache hash changes whenever any file changes. Since RUN pip install comes after, it must re-run. They reorder the Dockerfile to copy only requirements.txt first, run the install, and then copy the rest of the source code. Cache is preserved for dependency installation as long as requirements.txt doesn't change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T07:26:21.311972+00:00— report_created — created