Accidental Build Cache Invalidation
DK · Common Mistakessyntax
# Problem — COPY . . before RUN npm ci
COPY . .
RUN npm ciexample
# Every source code change re-runs npm ci (~30-60 seconds).
# Fix — copy manifests first:
COPY package.json package-lock.json ./
RUN npm ci
COPY . .Note Docker invalidates a layer's cache when any input changes. A broad COPY . . changes whenever ANY file in your project changes, nuking the cache for all subsequent layers. Order Dockerfile instructions from least-frequently to most-frequently changing.