-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (43 loc) · 1.37 KB
/
Dockerfile
File metadata and controls
63 lines (43 loc) · 1.37 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
# Multi-stage production Dockerfile for Next.js app
# Base image with Node 20
FROM node:20-alpine AS base
# Set working directory
WORKDIR /app
# Disable Next.js telemetry in containers
ENV NEXT_TELEMETRY_DISABLED=1
# Install system dependencies
RUN apk add --no-cache libc6-compat
# --- Dependencies stage ---
FROM base AS deps
# Copy dependency manifests
COPY package.json package-lock.json ./
# Install all dependencies (including dev) for building
RUN npm ci
# --- Builder stage ---
FROM base AS builder
ENV NODE_ENV=production
# Reuse node_modules from deps
COPY --from=deps /app/node_modules ./node_modules
# Copy the full project source
COPY . .
# Build the Next.js app
RUN npm run build
# --- Runner stage ---
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Install system dependencies
RUN apk add --no-cache libc6-compat
# Install only production dependencies for a smaller runtime image
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Copy the built Next.js app and required assets from the builder
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
# Copy Next.js config (used by the runtime for certain features)
# COPY --from=builder /app/next.config.ts ./next.config.ts
# Expose the Next.js port
EXPOSE 3000
# Use npm start to run the production server
CMD ["npm", "start"]