Build artifacts in one stage and copy only runtime output into the final stage.
Section: Common Patterns
Use multi-stage build
dockerfile
dockerfile
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY /app/dist /usr/share/nginx/htmlExplanation
Multi-stage builds keep runtime images smaller and cleaner.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Common Patterns
Cache dependencies effectively
Copy dependency manifests before application code to maximize layer cache reuse.