Report #85238
[bug\_fix] Dependency installation steps \(npm install, pip install\) re-run on every build, ignoring cache, even when dependencies haven't changed
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 has a Dockerfile that does \`COPY . /app\` followed by \`RUN npm install\`. Every time a source code file changes, \`docker build\` re-runs \`npm install\`, taking minutes. The developer tries \`--no-cache\` thinking their cache is corrupted, then tries BuildKit cache mounts, but the fundamental problem remains. The rabbit hole ends when they understand Docker's layer caching mechanism: if any file changed in the \`COPY . .\` step, the cache for that layer and \*all subsequent layers\* is invalidated. Since \`package.json\` is copied along with \`app.js\`, any change to \`app.js\` invalidates the \`npm install\` layer. The fix is to \`COPY package.json package-lock.json ./\` first, then \`RUN npm install\`, then \`COPY . .\`. This works because Docker computes a cache checksum based on the files copied, and layer execution only occurs if that checksum changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:39:19.546114+00:00— report_created — created