From dc1659463e630857fa8ae27465dba3b2502ddbf0 Mon Sep 17 00:00:00 2001 From: yuzhiheng Date: Thu, 4 Sep 2025 15:11:13 +0800 Subject: [PATCH] feat(docker): Docker build with multi-stage This will significantly reduce the size of the final image used for deployment. --- Dockerfile | 17 +++++++++++------ next.config.js | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index de34e1d..6088c3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,17 @@ -FROM --platform=linux/amd64 node:19-bullseye-slim - +FROM node:22-alpine AS deps WORKDIR /app - COPY . . +RUN yarn install --frozen-lockfile -RUN yarn install +FROM deps AS builder +WORKDIR /app +COPY . . RUN yarn build +FROM node:22-alpine AS runner +WORKDIR /app +COPY --from=builder --chown=nextjs:nodejs /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static EXPOSE 3000 - -CMD ["yarn","start"] +CMD ["node", "server.js"] diff --git a/next.config.js b/next.config.js index 34485cb..d6551de 100644 --- a/next.config.js +++ b/next.config.js @@ -16,6 +16,7 @@ const nextConfig = { // https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors ignoreBuildErrors: true, }, + output: 'standalone', } module.exports = nextConfig