Dockerfile.nodejs
attributes
| source_path | assets/Dockerfile.nodejs |
|---|---|
| source_sha256 | 31b44ecc9db4ef60a53f131f2e096e9940b152e83690c912825c14c383ced9a0 |
| source_url | https://github.com/docker/skills/blob/ce4693b88722334625780ca8e9d54201b2d96f6d/skills/docker-build-strategies/assets/Dockerfile.nodejs |
| supporting_skill_id | 40167 |
| upstream_revision | ce4693b88722334625780ca8e9d54201b2d96f6d |
# syntax=docker/dockerfile:1
# --- Production dependencies ---
FROM node:22-alpine AS deps
WORKDIR /src
# package.json/package-lock.json are bind-mounted (not COPY-ed): npm ci never
# rewrites them, so they never need to enter a layer.
# Registry credentials, if any, are mounted only for the duration of `npm ci`.
# `required=false` keeps the build green when no .npmrc is provided.
# Invoke with: docker buildx build --secret id=npmrc,src=<path-to-.npmrc> .
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev
# --- Build stage ---
FROM node:22-alpine AS build
WORKDIR /src
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
--mount=type=cache,target=/root/.npm \
npm ci
COPY . .
RUN npm run build
# --- Runtime stage ---
FROM node:22-alpine AS runtime
WORKDIR /app
RUN addgroup --system --gid 1001 appgroup && \
adduser --system --uid 1001 --ingroup appgroup appuser
# Production node_modules from deps stage, built output from build stage
COPY --from=deps --chown=appuser:appgroup /src/node_modules ./node_modules
COPY --from=build --chown=appuser:appgroup /src/dist ./dist
COPY --from=build --chown=appuser:appgroup /src/package.json .
USER appuser
EXPOSE 3000
LABEL org.opencontainers.image.source="<source-repository-url>"
ENTRYPOINT ["node", "dist/index.js"]
Children
No children yet.
Like how this is organised?
Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.