Builder stage
The first stage installs tools and creates the final build output.
This page shows how Docker can use one stage for building and another stage for running, which keeps the final image cleaner.
The first stage installs tools and creates the final build output.
The final stage copies only what is needed to run the app and leaves build clutter behind.
This is one of the best ways to create smaller, cleaner production images.
FROM node:18 AS builder
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
FROM node:18-alpine
WORKDIR /app
COPY --from=builder /app/dist /app/dist
CMD ["node", "dist/server.js"]Next page: Lesson 15 explains Docker Hub and registries so you can tag, push, and pull your own images properly.