Open2
Cloud RunにDockerを利用してNext.jsのweb appをデプロイ
Cloud Runへのデプロイが必要になった
これは困った
結論
次のDockerfile
, .dockerignore
を追加してPORT: 3000にデプロイ
# === base
FROM node:22-slim AS base
# === deps
FROM base AS deps
WORKDIR /app
COPY package* .
RUN npm install
# === builder
FROM base AS builder
WORKDIR /app
COPY /app/node_modules ./node_modules
COPY . .
RUN npm run build
# === prod deps
FROM base AS prod_deps
WORKDIR /app
COPY /app/package* ./
COPY /app/node_modules ./node_modules
RUN npm ci --omit=dev
# === runner
FROM gcr.io/distroless/nodejs22-debian12 AS runner
WORKDIR /app
ENV HOSTNAME=0.0.0.0
ENV NODE_ENV=production
ENV PORT=3000
COPY /app/package* ./
COPY /app/node_modules ./node_modules
COPY /app/public ./public
COPY /app/.next ./.next
USER nonroot
EXPOSE 3000
CMD ["node_modules/.bin/next", "start"]
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
リポジトリ