Back to MD Exchange
    Project Blueprintsdockermulti-stageoptimizationci-cd

    Docker Multi-Stage Build Templates

    Optimized Dockerfiles for Node.js, Python, Go, and Rust. Minimal images, proper caching, non-root users.

    S
    sarahkodiak|March 6, 2026|Updated Oct 8
    191 downloads11 stars

    Uploaded markdown content, not a verification of tool compatibility or results. Review the raw text, commands, and permissions before using it. Stars require an account.


    name: docker-multistage


    Docker Multi-Stage Builds

    Node.js (Next.js)

    Prerequisites: set output: 'standalone' in next.config.js. Serve public and .next/static from a CDN, or copy them into the runtime image's public and .next/static directories; standalone output does not include them automatically.

    FROM node:22-alpine AS builder
    WORKDIR /app
    COPY . .
    RUN npm ci && npm run build
    
    FROM node:22-alpine
    COPY --from=builder /app/.next/standalone ./
    USER 1001
    CMD ["node", "server.js"]
    

    Python (FastAPI) β€” ~120MB

    Go β€” ~15MB

    Rust β€” ~10MB

    All use non-root users and multi-stage for minimal attack surface.