-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile.prod
More file actions
59 lines (43 loc) · 1.83 KB
/
Dockerfile.prod
File metadata and controls
59 lines (43 loc) · 1.83 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 - OPTIMIZED
# Utilise le mode standalone de Next.js (pas besoin de node_modules)
# =============================================================================
# -----------------------------------------------------------------------------
# Stage 1: Builder (deps + build dans le même stage pour éviter copie lente)
# -----------------------------------------------------------------------------
FROM node:24.15.0-alpine AS builder
WORKDIR /app
# Copy dependency files first (pour le cache Docker)
COPY package*.json ./
# Génère un package-lock dans l'image (si absent) puis installe les deps
RUN npm install --package-lock-only && npm ci
# Copy source files
COPY . .
# Set production environment for build
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV NEXT_CONFIG_FILE=./next.config.prod.js
# Build the application (generates .next/standalone)
RUN npx next build --webpack
# -----------------------------------------------------------------------------
# Stage 3: Production Runner (MINIMAL)
# -----------------------------------------------------------------------------
FROM node:24.15.0-alpine AS runner
WORKDIR /app
# Production environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Create non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy standalone build (includes node_modules nécessaires)
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
# Copy static files
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
USER nextjs
EXPOSE 3000
# Standalone mode uses server.js directly (faster startup)
CMD ["node", "server.js"]