-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
58 lines (42 loc) · 1.43 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
# multi-stage build as deps
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat
#dpes의 app 디렉토리에 package.json 복붙
WORKDIR /app
COPY package.json postcss.config.js tailwind.config.ts yarn.lock ./
# yarn
RUN yarn --prefer-offline --frozen-lockfile
# 이미지 최적화
RUN yarn add sharp
# multi-stage build as builder
FROM node:18-alpine AS builder
# deps의 node_modules를 builder/app/node_modules로 복붙
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# 현재 디렉토리 확인
RUN ls -a
# 빌드
RUN yarn build
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# 사용자 그룹 nodejs 추가
# nodejs에 유저 nextjs 추가
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# builder에서 빌드했던 결과물 중 public, package.json 복붙
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/postcss.config.js ./postcss.config.js
COPY --from=builder /app/tailwind.config.ts ./tailwind.config.ts
# builder에서 빌드했던 결과물 중 static, standalone 복붙 소유자와 소유그룹도 변경
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# nextjs
USER nextjs
# 열어둘 포트 설정
EXPOSE 3000
# 이미지 안 환경변수 설정
ENV PORT 3000
CMD ["node", "server.js"]