Report #13525
[bug\_fix] Docker build cache invalidates on every source code change, causing dependency installation steps \(e.g., npm install, pip install\) to re-run entirely
Reorder the Dockerfile to copy dependency definition files \(package.json/package-lock.json or requirements.txt\) first, run the dependency installation, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because it re-downloads hundreds of npm packages. They assume Docker caching is broken. They inspect the Dockerfile and see 'COPY . .' followed by 'RUN npm install'. Because the application source code changes every commit, the 'COPY . .' layer hash changes. Since 'RUN npm install' comes after, its cache is invalidated by the changed parent layer. The fix separates the dependency resolution from the source copy. By copying only package.json first, the 'RUN npm install' layer only invalidates when dependencies actually change. Then 'COPY . .' runs afterward. This restores the cache and drops build times to seconds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:54:44.163813+00:00— report_created — created