Report #51091
[bug\_fix] Dependency installation step \(npm install, pip install, apt-get install\) runs fully on every code change, ignoring Docker build cache.
Copy only dependency manifest files \(e.g., package.json, requirements.txt\) before the install command, then copy the rest of the source code.
Journey Context:
A developer notices their Docker build takes 5 minutes every time they change a single line of code. They assume Docker caching is broken. They start tinkering with --no-cache flags, rebuilding base images, and deleting local images. Finally, they look closely at the Dockerfile and see \`COPY . /app\` followed by \`RUN npm install\`. They realize Docker calculates a cache hash for each layer based on its input files. Because ALL source code is copied before npm install, ANY change to ANY source file invalidates the cache for the npm install layer. The fix works by splitting the copy: first copy only package.json and package-lock.json, run npm install, and then \`COPY . /app\`. Now, the expensive install layer is only invalidated when the lockfile changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T16:14:47.648582+00:00— report_created — created