skip to content

Docker layers: 6 rules for smaller images


6 rules

  1. Use a small base (alpine/distroless when possible)
  2. Copy only what you need (use .dockerignore)
  3. Install deps before copying app source
  4. Combine commands to reduce layers
  5. Use multi-stage builds
  6. Pin versions to avoid surprise rebuilds
FROM node:24-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM gcr.io/distroless/nodejs24-debian12
COPY --from=build /app/dist /app
CMD ["/app/index.js"]