Report #8050
[bug\_fix] Docker build cache invalidated on every code change, causing slow reinstalls of dependencies
Copy only the dependency manifest files \(e.g., package.json, requirements.txt\) and run the install step BEFORE copying the rest of the application source code.
Journey Context:
A developer notices their Docker builds take 5 minutes every time they change a single line of code. Their Dockerfile has COPY . /app followed by RUN npm install. Because the application source code changes frequently, the COPY layer is always invalidated. Since RUN npm install comes after COPY, its cache is also invalidated, forcing a full dependency reinstall every time. The debugging journey involves understanding Docker's layer caching: instructions are cached, but if a prior layer changes, all subsequent layers are rebuilt. The fix is to reorder the instructions. First, COPY package.json package-lock.json ./ and then RUN npm install. Only after the dependencies are installed and cached do COPY . /app. Now, npm install is only re-run when the package files change, drastically speeding up builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:23:18.568691+00:00— report_created — created