-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
66 lines (47 loc) · 1.41 KB
/
Dockerfile
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
60
61
62
63
64
65
66
# Build stage
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Install dependencies
RUN npm ci
# Copy the rest of the application code
COPY . .
# Install sharp for improved image optimization
RUN npm install sharp
# Build the Next.js application
RUN npm run build
# Production stage
FROM node:18-alpine AS runner
# Set working directory
WORKDIR /app
# Set node environment to production
ENV NODE_ENV=production
# Set timezone to KST
ENV TZ=Asia/Seoul
# Install tzdata package and set timezone
RUN apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone
# Add a non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files from build stage
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# Copy the built app
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy the .env.local file
COPY --from=builder /app/.env.local ./
# Set the correct permission for prerender cache
RUN mkdir -p .next
RUN chown nextjs:nodejs .next
# Switch to non-root user
USER nextjs
# Expose the port the app runs on
EXPOSE 3000
# Start the application
CMD ["node", "server.js"]