-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (43 loc) · 1.44 KB
/
Dockerfile
File metadata and controls
59 lines (43 loc) · 1.44 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
# Production Dockerfile for Next.js with native dependencies
FROM node:22-alpine AS base
# Install build dependencies for native modules (better-sqlite3) and ffmpeg
RUN apk add --no-cache \
python3 \
make \
g++ \
ffmpeg
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy package files for dependency installation
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# Install dependencies
RUN pnpm install --frozen-lockfile
# Build stage
FROM base AS builder
# Copy source code
COPY . .
# Build the application
RUN pnpm build
# Production stage
FROM base AS runner
# Don't run as root for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy built application
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone .
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# Create data directory and set permissions
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
USER nextjs
# Expose Next.js production server port
EXPOSE 3333
# Environment variables for production
ENV NODE_ENV=production
ENV PORT=3333
ENV HOSTNAME=0.0.0.0
# Start the production server
# - exec: replaces shell so SIGTERM from Docker reaches Node for graceful shutdown
# - 2>&1: merges stderr into stdout so Docker logs don't show every line twice
CMD exec node server.js 2>&1