Report #60677
[bug\_fix] Docker layer cache invalidated on every code change, forcing dependency reinstallation
Reorder Dockerfile instructions: copy only dependency manifests \(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 every time they change a single line of code. They look at the Docker output and see pip install or npm install running from scratch every time. They assumed Docker caching would skip this. They examine the Dockerfile and see COPY . . followed by RUN npm install. They realize that any change to any source file alters the layer created by COPY . ., which invalidates the cache for all subsequent layers, including the expensive dependency installation layer. By splitting the copy into two steps—first copying only the dependency manifests, then running the installation, and finally copying the source code—the dependency installation layer is only invalidated when the dependency manifest itself changes. The fix works because Docker builds layers sequentially, and a cache miss in a parent layer forces a rebuild of all child layers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:19:53.758818+00:00— report_created — created