Generate production-ready Dockerfiles with multi-stage builds, non-root users, and best practices.
# Stage 1: Build FROM node:20-alpine AS builder WORKDIR /app # Copy dependency files COPY package*.json ./ # Install all dependencies (including dev) RUN npm ci # Copy source code COPY . . # Build RUN npm run build # Stage 2: Production FROM node:20-alpine AS production WORKDIR /app # Copy production dependencies and built files COPY --from=builder /app/package*.json ./ RUN npm ci --only=production COPY --from=builder /app/dist ./dist # Run as non-root user RUN addgroup -S appgroup && adduser -S appuser -G appgroup USER appuser EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1 CMD ["node", "dist/index.js"]

New tutorials, open-source projects, and deep dives on coding agents - delivered weekly.