Multi-stage builds allow you to use multiple FROM statements in a single Dockerfile to separate build and runtime environments. You can build an application in one stage and copy only the final output to a minimal base image in a later stage. This results in smaller, cleaner images and avoids including build tools and dependencies in the production image.

Dockerfile
FROM node:20 AS builder
WORKDIR /app
COPY . .
RUN npm install && npm run build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html