-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (42 loc) · 1.32 KB
/
Dockerfile
File metadata and controls
59 lines (42 loc) · 1.32 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
# ================================
# 1️⃣ Base stage: dependencies
# ================================
FROM node:22.20.0-slim AS deps
# Install pnpm globally
RUN corepack enable && corepack prepare pnpm@latest --activate
# Set working directory
WORKDIR /app
# Copy only package files to install dependencies
COPY package.json pnpm-lock.yaml* ./
# Install dependencies (cached layer)
RUN pnpm install --frozen-lockfile
# ================================
# 2️⃣ Builder stage
# ================================
FROM node:22.20.0-slim AS builder
WORKDIR /app
# Enable pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy node_modules from deps
COPY --from=deps /app/node_modules ./node_modules
# Copy rest of the source code
COPY . .
# Build the Next.js app
RUN pnpm build
# ================================
# 3️⃣ Runtime stage
# ================================
FROM node:22.20.0-slim AS runner
WORKDIR /app
# Enable pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
ENV NODE_ENV=production
ENV PORT=3000
# Copy built output and dependencies
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
# Expose port and run
EXPOSE 3000
CMD ["pnpm", "start"]