feat(docker): Docker build with multi-stage

This will significantly reduce the size of the final image used for deployment.
This commit is contained in:
yuzhiheng
2025-09-04 15:11:13 +08:00
parent b35f0effe5
commit dc1659463e
2 changed files with 12 additions and 6 deletions

View File

@ -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"]