S
Supanote
Sign in Sign up

Multi-Stage Production Node.js Dockerfile with Distroless

plain (dockerfile) 1 month ago · 28 lines · 230 views
Verified Blueprint Docker

Secure, minimal Node.js Dockerfile using multi-stage build, npm cache mounting, non-root user, and Google distroless runtime.

Quick Fetch
1# Stage 1: Dependency resolution and compilation
2FROM node:20-alpine AS deps
3WORKDIR /app
4COPY package*.json ./
5RUN --mount=type=cache,target=/root/.npm \
6 npm ci --omit=dev --ignore-scripts
7
8# Stage 2: Application builder (if TypeScript/bundler required)
9FROM node:20-alpine AS builder
10WORKDIR /app
11COPY package*.json ./
12COPY --from=deps /app/node_modules ./node_modules
13COPY . .
14# RUN npm run build
16# Stage 3: Ultra-minimal hardened runtime
17FROM gcr.io/distroless/nodejs20-debian12 AS runner
18WORKDIR /app
19ENV NODE_ENV=production
20ENV PORT=3000
22COPY --from=deps /app/node_modules ./node_modules
23COPY --from=builder /app ./
25USER nonroot
26EXPOSE 3000
27CMD ["server.js"]

No replies yet

Every reply is a note. Start a discussion, ask a question, or attach a code snippet.

Related Docker & DevOps & Infrastructure Blueprints

Production-ready configurations and diagnostics from the verified Supanote library.

All DevOps & Infrastructure →
Interactive Developer Workbench: Docker Container & JSON Log Viewer

Inspect Docker Compose stdout/stderr streams, JSON log drivers, ANSI color codes, and multi-line stack traces.

Open Docker Log Viewer →

Share Note

Open
Download SVG
Social Card Preview
Open on mobile
Point your phone camera to open this note directly

Report this note

Notification