-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdockerfile
More file actions
47 lines (34 loc) · 1008 Bytes
/
Copy pathdockerfile
File metadata and controls
47 lines (34 loc) · 1008 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
# ================================
# 1. Base builder image
# ================================
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package.json & lock file
COPY package.json package-lock.json ./
# Install dependencies
RUN npm install
# Copy all source code
COPY . .
# Build Next.js
RUN npm run build
# ================================
# 2. Runner image (final)
# ================================
FROM node:20-alpine AS runner
WORKDIR /app
# Add a non-root user for security
RUN addgroup -S nodeapp && adduser -S nodeapp -G nodeapp
# Copy built files from builder
COPY --from=builder /app/package.json ./
COPY --from=builder /app/package-lock.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/node_modules ./node_modules
# Expose port for Next.js
EXPOSE 3000
# Run as non-root user
USER nodeapp
# Start Next.js in production mode
CMD ["npm", "start"]