Report #93318
[bug\_fix] Docker build cache invalidated on every code change causing slow dependency installs
Copy only dependency manifests \(e.g., package.json, requirements.txt\) first, run the dependency installation, and then copy the rest of the source code.
Journey Context:
A developer notices their CI builds take 10 minutes even if they just change a single line of application code. They inspect the Dockerfile and see COPY . . followed by RUN npm install. They realize Docker evaluates the filesystem diff at each COPY instruction. Since COPY . . includes all source files, any change to any file invalidates the cache for that layer and all subsequent layers, including the slow npm install. By splitting the copy into two steps—first copying only package.json and package-lock.json, running npm install, and then copying the rest of the code—the dependency layer is only invalidated when the dependency manifests change, restoring the cache hit for code-only changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:13:19.641342+00:00— report_created — created