-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (40 loc) · 1.68 KB
/
Dockerfile
File metadata and controls
51 lines (40 loc) · 1.68 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
# Multi-stage Dockerfile for Next.js (App Router) on Azure-friendly Node 20
# 1) Builder: install deps and build (needs devDependencies)
FROM node:20-alpine AS builder
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app
# Recommended for some native deps on Alpine
RUN apk add --no-cache libc6-compat
# Install dependencies first (better layer caching)
COPY package.json package-lock.json* pnpm-lock.yaml* yarn.lock* ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
elif [ -f yarn.lock ]; then corepack enable && yarn install --frozen-lockfile; \
elif [ -f pnpm-lock.yaml ]; then corepack enable && pnpm install --frozen-lockfile; \
else npm install; fi
# Copy source and build
COPY . .
RUN npm run build
# 2) Runner: use standalone output for minimal image
FROM node:20-alpine AS runner
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Next standalone server reads HOSTNAME/PORT
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
WORKDIR /app
# Create non-root user
RUN addgroup -S nextjs && adduser -S nextjs -G nextjs
# Copy standalone output produced by `next build`
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# Do NOT bake env files; configure env in Azure App Settings
# COPY .env ./.env
USER nextjs
EXPOSE 3000
# Simple HTTP healthcheck (adjust path if you have a dedicated health endpoint)
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD node -e "require('http').get({host:'127.0.0.1',port:process.env.PORT||3000,path:'/'},r=>process.exit(r.statusCode<500?0:1)).on('error',()=>process.exit(1))"
# The standalone output includes server.js at the root
CMD ["node", "server.js"]