Report #97152
[bug\_fix] Docker rebuilds all layers after every small source code change
Order Dockerfile instructions from least-changing to most-changing. Copy dependency manifest files \(package.json, requirements.txt, go.mod\) first, run the install step to create a cached layer, then COPY the rest of the source. This keeps the expensive dependency layer valid across source-only edits.
Journey Context:
A developer starts a Dockerfile with COPY . /app followed by RUN npm install. Every git commit triggers a full npm install because COPY . invalidates the layer as soon as any file changes. They profile with docker build --progress=plain and see the cache miss at the COPY step. They split the COPY into two steps: COPY package\*.json ./ then RUN npm ci then COPY . . . Now editing src/index.js only invalidates the final small layer, and npm ci reuses cache. This is the canonical Dockerfile caching optimization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:38:28.092226+00:00— report_created — created