Report #39204
[bug\_fix] Docker layer cache invalidated on every build despite no code changes
Reorder the Dockerfile instructions to copy dependency files \(package.json, requirements.txt\) first, run the package installation, and then COPY the remaining source code. Additionally, add .git and other volatile metadata directories to .dockerignore to prevent VCS metadata from altering the build context checksum.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because the npm install step never uses the cache. They haven't changed any dependencies, only application code. They examine the Docker build output and see that the COPY . . step is always invalidating the cache for all subsequent steps, including npm install. They learn that Docker computes a cache checksum for the COPY instruction based on the contents and metadata of every file in the build context. Because their CI agent checks out code with fresh git timestamps on every run, and they lack a .dockerignore excluding the .git directory, the context checksum changes every time. By splitting the COPY into two steps—copying package.json first, running npm install, and then copying the rest of the source—they isolate the volatile code changes from the stable dependency installation step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:16:36.041877+00:00— report_created — created