Module 9: Production Optimization
In production, image size matters. A smaller image is faster to download and more secure (fewer tools for hackers).
Step 1: Multi-Stage Builds
Multi-stage builds allow you to use one large image for building your app, and a tiny image for running it.
Example:
# Stage 1: Build
FROM node:18 AS builder
WORKDIR /app
COPY . .
RUN npm install && npm run build
# Stage 2: Production
FROM node:18-alpine
COPY --from=builder /app/dist /app/dist
CMD ["node", "/app/dist/main.js"]
Mission: Create a Dockerfile with two FROM instructions to practice the multi-stage pattern.
booting...