What are multi-stage builds in Docker, and why are they useful?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sarthak VarshneyRank #46 · 32K reputationPosted May 27, 2025, 6:34 AM EDT
Multi-stage builds allow you to use multiple
FROMstatements 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.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