Report #29777
[bug\_fix] Dependency installation steps \(e.g., npm install, pip install\) run completely from scratch on every code change, causing extremely slow builds.
Copy only the dependency definition files \(e.g., package.json, requirements.txt\) and run the installation command \*before\* copying the rest of the application source code.
Journey Context:
A developer notices their Docker builds take 10 minutes because \`npm install\` re-downloads hundreds of packages every time a single line of application code changes. They assume Docker caching is broken. They inspect the Dockerfile and see \`COPY . /app\` followed by \`RUN npm install\`. Because the \`COPY .\` layer includes all source code, any change to any source file invalidates the cache for that layer and all subsequent layers, including the \`RUN npm install\` layer. The fix is to reorder the instructions: first \`COPY package.json package-lock.json ./\`, then \`RUN npm install\`, and finally \`COPY . .\`. This way, the expensive installation layer is only invalidated when the lockfiles change, perfectly leveraging Docker's layer caching mechanism.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:22:09.867663+00:00— report_created — created