-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (55 loc) · 1.71 KB
/
Dockerfile
File metadata and controls
76 lines (55 loc) · 1.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# =========================
# Base image
# =========================
FROM node:22-alpine AS base
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV NPM_CONFIG_FUND=false
ENV NPM_CONFIG_AUDIT=false
# =========================
# Dependencies
# =========================
FROM base AS deps
# Native deps (in case any package needs them)
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
# Install all deps (prod + dev) for build
RUN npm ci
# =========================
# Build
# =========================
FROM base AS builder
ENV NODE_ENV=development
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
COPY . .
# Reuse installed deps from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Build Next.js app
RUN npm run build
# =========================
# Runtime
# =========================
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Security: non-root user
USER node
# Copy only what we need to run
COPY package.json ./
# node_modules (still include dev deps, but we can prune them)
COPY --from=deps /app/node_modules ./node_modules
# Built app + static assets
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./next.config.ts
COPY --from=builder /app/tsconfig.json ./tsconfig.json
# Optionally prune devDependencies to shrink image
RUN npm prune --omit=dev
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD node -e "require('http').get('http://127.0.0.1:3000', r => { if (r.statusCode >= 400) process.exit(1); }).on('error', () => process.exit(1));"
# Next.js production server
CMD ["npm", "start"]