Report #41051
[bug\_fix] Dependency installation layer invalidates and rebuilds on every source code change
Reorder the Dockerfile instructions: copy only the dependency definition files \(e.g., package.json, requirements.txt\) first, run the installation step, and then copy the rest of the source code.
Journey Context:
A developer notices their Docker builds take 5 minutes every time they change a single line of code. They assume Docker caching is broken. They investigate and find the \`RUN npm install\` step runs every time. The root cause is that they placed \`COPY . /app\` before \`RUN npm install\`. Since \`COPY . /app\` includes all source code, any change to any source file invalidates that layer, which invalidates all subsequent layers including the dependency installation. The fix works because Docker evaluates layers sequentially; by only copying the rarely-changing dependency files first, the \`npm install\` layer can be reused from the cache as long as the dependency files remain unchanged.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:22:22.994856+00:00— report_created — created