Use a minimal Alpine runtime image without npm

The node:24-slim image had 262 known vulnerabilities (Trivy), almost
all in Debian system packages, plus 21 in the npm bundled with Node.
None were in the app's own dependencies. The runtime now uses
node:24-alpine with npm, npx, corepack and yarn removed and Alpine
security updates applied: 0 known vulnerabilities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 18:34:49 +02:00
co-authored by Claude Opus 5.5
parent 95c27e7353
commit b338e1abb4
+7 -2
View File
@@ -1,4 +1,4 @@
FROM node:24-slim AS base FROM node:24-alpine AS base
WORKDIR /app WORKDIR /app
RUN corepack enable RUN corepack enable
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
@@ -11,7 +11,12 @@ RUN pnpm build
FROM base AS prod-deps FROM base AS prod-deps
RUN pnpm install --frozen-lockfile --prod RUN pnpm install --frozen-lockfile --prod
FROM node:24-slim AS runner FROM node:24-alpine AS runner
# The app only needs the node binary. npm, npx, corepack and yarn ship with the base image and carry
# most of its known vulnerabilities, so they're removed; pending Alpine security updates are applied.
RUN apk upgrade --no-cache \
&& rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack \
/usr/local/bin/yarn /usr/local/bin/yarnpkg /opt/yarn-*
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production \ ENV NODE_ENV=production \
PORT=3000 \ PORT=3000 \