Multi-Stage Production Node.js Dockerfile with Distroless
plain (dockerfile)
13 hours ago
·
28 lines
·
6 views
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
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"]
Replies 0
No replies yet
Every reply is a note. Start a discussion, ask a question, or attach a code snippet.
Notification