Report #62029
[bug\_fix] Docker build cache invalidates completely on every code change, forcing full dependency reinstallation.
Reorder the Dockerfile to copy dependency definition files \(e.g., package.json, requirements.txt\) first, run the package installation step, and then copy the rest of the source code.
Journey Context:
A developer builds a Node.js image. The first build takes 5 minutes to install npm packages. They change a single line in app.js, rebuild, and it takes 5 minutes again. They assume Docker caching is broken. After inspecting the build output, they notice the 'RUN npm install' step is never 'CACHED'. They realize that 'COPY . .' copies all source code before the install step. Since app.js changed, the 'COPY . .' layer checksum changes, invalidating that layer and all subsequent layers, including the npm install step. By splitting the copy into two steps—copying only package.json and package-lock.json first, running npm install, and then copying the remaining source code—the expensive install layer only invalidates when the dependency definitions change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:36:12.314814+00:00— report_created — created