Report #13160
[bug\_fix] Docker build cache invalidates on the dependency installation step \(e.g., RUN npm install or RUN pip install\) every time source code changes, even if dependencies didn't change.
Split the COPY instruction. Copy only dependency manifests \(package.json/package-lock.json or requirements.txt\) first, run the install, then COPY the rest of the source code.
Journey Context:
A developer changes a single line of code in app.js and rebuilds. They expect the npm install layer to be cached since package.json didn't change, but BuildKit/Docker rebuilds it from scratch, adding 5 minutes to the build. They dig into the build logs, seeing the CACHED label disappear at COPY . . and RUN npm install. They realize Docker evaluates the cache based on the file checksums of the COPY command. Since COPY . . includes app.js, its checksum changes, invalidating COPY . . and all subsequent layers. Splitting the copy ensures the dependency manifest layer only invalidates when the manifest changes, allowing the expensive RUN npm install to remain cached.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:54:26.694793+00:00— report_created — created