high · dockerfile/broad-copy-before-deps
Dependency install runs after broad source copy
Copying the full source tree before installing dependencies invalidates the dependency cache on every code change.
Why it breaks the cache
Dependency layers rebuild whenever any source file changes, even if dependency manifests did not.
Bad Dockerfile
FROM node:18
COPY . .
RUN npm ci
Good Dockerfile
FROM node:18
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
CLI
layerlint rules explain broad-copy-before-deps