-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
45 lines (30 loc) · 1007 Bytes
/
Dockerfile
File metadata and controls
45 lines (30 loc) · 1007 Bytes
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
# 1. Build stage
FROM node:22 AS builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Install dependencies with exact versions and clean cache to reduce size
RUN npm ci && npm cache clean --force
COPY . .
# Set environment variable for Next.js to build in production mode
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Run build
RUN npm run build
# 2. Runner stage
FROM node:22-slim AS runner
WORKDIR /app
RUN groupadd --system --gid 1001 nodejs
RUN useradd --system --uid 1001 --gid 1001 nextjs
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=builder /app/next.config.ts ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# Requires output: standalone in next.config.ts
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Switch to non-root user
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]