-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (39 loc) · 1.18 KB
/
Dockerfile
File metadata and controls
52 lines (39 loc) · 1.18 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
# ---- Dependencies Stage ----
FROM node:20-alpine AS deps
# Add libc6-compat for sharp/node compatibility on Alpine
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies separately for caching
COPY package*.json ./
RUN npm ci --frozen-lockfile
# ---- Build Stage ----
FROM node:20-alpine AS builder
WORKDIR /app
# Set BACKEND API URL at build time
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
COPY --from=deps /app/node_modules ./node_modules
# Copy source code
COPY . .
# Build Next.js
RUN npm run build
# ---- Production Stage ----
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Default to port 3000, override via ENV
ENV PORT=3000
# Create non-root users for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Set permissions for Next.js cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy files from the build stage
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE $PORT
# Run via Node
CMD ["sh", "-c", "node server.js -p $PORT"]