-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (33 loc) · 1000 Bytes
/
Copy pathDockerfile
File metadata and controls
47 lines (33 loc) · 1000 Bytes
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
# syntax=docker/dockerfile:1
# ---------- Base Image ----------
FROM node:20-alpine AS base
# Optional: compatibility library
RUN apk add --no-cache libc6-compat
WORKDIR /app
# ---------- Dependencies Layer ----------
FROM base AS deps
COPY package.json package-lock.json* ./
RUN npm ci
# ---------- Builder Layer ----------
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the Next.js app
ENV NEXT_DISABLE_ESLINT true
RUN npm run build
# ---------- Runner Layer ----------
FROM base AS runner
WORKDIR /app
# Use a non-root user for security
RUN addgroup -g 1001 -S nodejs && adduser -u 1001 -S nextjs -G nodejs
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Copy only necessary files
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 3000
CMD ["node", "server.js"]