-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (37 loc) · 1.08 KB
/
Dockerfile
File metadata and controls
47 lines (37 loc) · 1.08 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
# Stage 1: Build the application
FROM node:20-alpine AS builder
WORKDIR /app
# Disable Next.js telemetry during build
ENV NEXT_TELEMETRY_DISABLED=1
# Copy package files
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build Next.js application (static export to /app/out)
RUN npm run build
# Stage 2: Serve static files with nginx
FROM nginx:alpine AS runner
# Copy custom nginx config for SPA routing
RUN echo 'server { \
listen 80; \
listen [::]:80; \
root /usr/share/nginx/html; \
index index.html; \
location / { \
try_files $uri $uri/ $uri.html /index.html; \
} \
location /_next/static/ { \
expires 1y; \
add_header Cache-Control "public, immutable"; \
} \
gzip on; \
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; \
}' > /etc/nginx/conf.d/default.conf
# Copy static files from builder
COPY --from=builder /app/out /usr/share/nginx/html
# Expose port
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]