Good Code
The good version lets the dependency install layer stay cached when only source files change.
Lesson 03
Order Dockerfile instructions so dependency layers are reused when source files change.
FROM node:22-alpine AS app
WORKDIR /app
# Copy dependency files first so npm ci can stay cached.
COPY package.json package-lock.json ./
RUN npm ci
# Source changes happen after dependency install.
COPY src ./src
COPY public ./public
RUN npm run buildFROM node:22-alpine AS app
WORKDIR /app
# Copying everything first makes any source edit break the install cache.
COPY . .
RUN npm install
RUN npm run buildThe good version lets the dependency install layer stay cached when only source files change.
The bad version copies the whole project before installing dependencies. Any source edit can invalidate the expensive install layer.