How Docker layers actually work (and why your build is slow)
Every instruction in a Dockerfile is a layer, and every layer is cached until something above it changes.
Copy dependency manifests before source code. Install before you copy the rest. That’s the whole trick.
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build