Docker images that build in seconds
Layer order is the whole trick. Copy your lockfile before your source, and stop reinstalling the world.
5 Jun 2026 · 5 min readDevOpsDockerCI
A six-minute image build is rarely doing six minutes of work. It's usually redoing a two-minute install because a layer above it changed.
docker
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci # cached until the lockfile changes
FROM node:22-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:22-alpine
WORKDIR /app
COPY --from=build /app/.next/standalone ./
CMD ["node", "server.js"]- Copy the lockfile alone before the source, so edits to a component don't invalidate the install.
- Use a multi-stage build so build tools never reach the final image.
- Add a .dockerignore. Shipping node_modules and .git into the context is a surprisingly common quiet tax.
Ours went from around six minutes to under forty seconds on a normal code change, which changed how often people were willing to deploy.