Report #5689
[bug\_fix] Docker cache invalidates on the RUN npm install step every time source code changes, forcing a full dependency reinstall.
Copy the package.json and package-lock.json \(or requirements.txt, go.sum, etc.\) first, run the package install step, and then copy the rest of the source code.
Journey Context:
A developer notices their local builds take 5 minutes every time they change a single line of application code. They assume Docker caching is broken or flaky. They test by running the same build twice and see it's fast the second time, but the moment they edit a source file, the cache breaks. They inspect the Dockerfile and see 'COPY . .' followed by 'RUN npm install'. They realize Docker computes a checksum for the context of the COPY command. Since ANY source file change alters the checksum of 'COPY . .', that layer and all subsequent layers are invalidated, forcing the slow 'npm install' to re-run. The fix separates the dependency specification from the source code, ensuring the expensive install step only runs when package.json changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:53:05.183630+00:00— report_created — created