Report #100552
[bug\_fix] Every source-code change invalidates dependency installation and rebuilds take minutes.
Reorder the Dockerfile so dependency manifests are copied and installed before the application source: \`COPY package.json package-lock.json ./\` then \`RUN npm ci\`, then \`COPY . .\`. This keeps the npm install layer cached unless the manifests change.
Journey Context:
A Node.js project starts with a Dockerfile that copies the whole repo at once: \`COPY . /app\` followed by \`RUN npm ci\`. On the first build everything works. Then a developer edits \`src/index.js\` and rebuilds; Docker reinstalls every npm package. They suspect the cache is broken and try \`docker build --no-cache\`, making it worse. They add \`.dockerignore\` entries but the problem persists. The real issue is layer-cache invalidation order: once any file in the build context referenced by a COPY changes, that layer and every layer after it are rebuilt. Because \`COPY .\` happens before \`npm ci\`, any code change invalidates the install step. Copying only \`package.json\` and \`package-lock.json\` first lets Docker hash a tiny, rarely-changing input for the install layer, so source-only edits reuse the cached \`node\_modules\` layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T04:42:09.568365+00:00— report_created — created