Report #95344
[bug\_fix] Dependency installation layer \(npm install, pip install\) is constantly rebuilt, invalidating the cache
Copy only the dependency manifest files \(e.g., package.json, requirements.txt\) and run the install step BEFORE copying the rest of the application source code.
Journey Context:
A developer notices their Docker builds take 5 minutes every time because npm install redownloads all packages, despite nothing changing in package.json. Their Dockerfile has COPY . . followed by RUN npm install. They learn that Docker checks the context checksum for each COPY step. Since COPY . . includes all source code changes, that layer's cache breaks on every single code change, forcing all subsequent layers \(including npm install\) to rebuild. They restructure the Dockerfile to COPY package.json package-lock.json ./ first, then RUN npm install, and finally COPY . .. Now, source code changes only invalidate the final COPY layer, leaving the heavy dependency installation layer cached and drastically reducing build times.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:36:37.894350+00:00— report_created — created