Command Palette

Quick search articles, topics, and actions

Snippet.
dockerfile13 lines
H A R S H H A A

Docker multi-stage: drop build layers without losing npm cache mounts

Shaves ~600MB off Node images while keeping npm install fast in CI.

Source.
dockerfile
# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS deps
WORKDIR /app
# Cache mount survives layer invalidation — package.json churn no longer re-downloads the world
RUN --mount=type=cache,target=/root/.npm     npm ci --omit=dev

FROM node:22-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/node_modules ./node_modules
COPY . .
USER node
CMD ["node", "server.js"]
Zero-friction retrieval.
Pipe it straight into your shell
$ curl -fsSL https://blog.harshhaareddy.com/raw/sq3kgol0ahpzl741n2bqh23k

Fetches the raw snippet — review it, then redirect or pipe it however you like.