Report #99133
[bug\_fix] Docker rebuilds dependency install step on every source code change
Order Dockerfile instructions from least-frequently-changed to most-frequently-changed. Copy dependency manifests \(\`package\*.json\`, \`requirements.txt\`, \`go.mod\`, \`Cargo.toml\`\) before copying the rest of the source, and run the install command immediately after. Then add \`COPY . .\` and the build command. This keeps the dependency layer cached independently from the source layer.
Journey Context:
A developer starts with \`COPY . .\` followed by \`RUN npm ci\`. Every time they edit \`src/App.tsx\`, Docker re-runs \`npm ci\` and downloads hundreds of megabytes again. They assume Docker caching is broken. After reading the build output, they notice that \`COPY . .\` is not marked CACHED because a source file changed, and every instruction after it is invalidated. They restructure the Dockerfile: \`COPY package\*.json ./\`, \`RUN npm ci\`, then \`COPY . .\`, then \`RUN npm run build\`. Now \`npm ci\` is skipped on most edits and only the build step re-runs. They also add a good \`.dockerignore\` so unrelated files do not accidentally invalidate the layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:37:46.114991+00:00— report_created — created