Report #1850
[bug\_fix] Every code change reinstalls dependencies; the layer cache for npm/pip/apt is never reused because an earlier COPY invalidates it.
Reorder the Dockerfile so the least-changing instructions come first. Copy only lock/manifest files, install dependencies, then COPY the rest of the source. This way source changes invalidate only the final COPY layer and the dependency layer remains cached.
Journey Context:
A Node.js Dockerfile starts with COPY . . followed by RUN npm install. Every tiny code edit causes npm install to run again. Using --progress=plain shows the cache miss happens at COPY . . because the source changed. The developer rewrites the Dockerfile to COPY package\*.json ./, then RUN npm ci, then COPY . .. Now only package.json or package-lock.json changes trigger a reinstall, and normal code edits reuse the cached dependency layer. The root cause is that once any layer is invalidated, every subsequent layer must be rebuilt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T08:50:47.166409+00:00— report_created — created