-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.nextjs.prod
48 lines (33 loc) · 1.17 KB
/
Dockerfile.nextjs.prod
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
# 参考: https://zenn.dev/kazumax4395/articles/427cc791f6145b
# Build layer
# devDependenciesも含めてinstallし、
# .next/ 内にNext.js関連の仕組みが動作するのに必要なファイルを出力
FROM node:20-slim AS build
WORKDIR /app
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN NEXT_BUILD=1 pnpm next build
RUN ls -la .next
# Package install layer
# dependencies をインストール、動作に必要なライブラリだけを取得する
FROM node:20-slim AS node_modules
WORKDIR /app
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod
# Deploy layer
#
# イメージサイズやセキュリティの視点からおすすめのイメージとのこと
FROM gcr.io/distroless/nodejs20-debian12
#FROM gcr.io/distroless/nodejs20:debug
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
COPY package.json next.config.mjs ./
COPY --from=build /app/public ./public
COPY --from=build /app/.next ./.next
COPY --from=node_modules /app/node_modules ./node_modules
#RUN ls -la ./.next
CMD ["./node_modules/next/dist/bin/next", "start"]