-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (39 loc) · 1.65 KB
/
Copy pathDockerfile
File metadata and controls
47 lines (39 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# syntax=docker/dockerfile:1.7
# Next.js 16 standalone (distDir=dist), multi-arch via BuildKit
FROM --platform=$BUILDPLATFORM node:22-alpine3.24 AS builder
WORKDIR /app
# npm's defaults allow 970s of silence per hung registry socket; these bound it to 115s
ENV NEXT_TELEMETRY_DISABLED=1 \
NPM_CONFIG_FETCH_TIMEOUT=30000 \
NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=15000 \
NPM_CONFIG_LOGLEVEL=http
ARG GITHUB_ACTOR
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --no-audit --no-fund
COPY . .
RUN --mount=type=cache,target=/app/dist/cache \
npm run build && \
if node -p "require('./dist/required-server-files.json').config.images.unoptimized" | grep -q true; then \
rm -rf dist/standalone/node_modules/@img dist/standalone/node_modules/sharp; \
fi
FROM node:22-alpine3.24 AS runner
WORKDIR /app
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0
RUN apk upgrade --no-cache && \
rm -rf /usr/local/lib/node_modules/npm \
/usr/local/lib/node_modules/corepack \
/usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack \
/usr/local/bin/yarn /usr/local/bin/yarnpkg /opt/yarn-v* && \
addgroup -S -g 1001 nodejs && \
adduser -S -u 1001 -G nodejs nextjs
COPY --from=builder --chown=nextjs:nodejs /app/dist/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/dist/static ./dist/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/scripts/server-entry.js ./server-entry.js
USER nextjs
EXPOSE 3000
ENTRYPOINT ["node", "server-entry.js"]