Files
ai-portal/Dockerfile
T
2026-06-17 12:34:38 +08:00

41 lines
1.2 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
FROM node:22-alpine AS base
RUN apk add --no-cache openssl
WORKDIR /app
# 阶段1:全量安装依赖(含prisma CLI、wasm、迁移工具)
FROM base AS deps
COPY package*.json ./
COPY prisma ./prisma
RUN npm ci
# 构建阶段提前生成客户端、wasm文件
RUN npx prisma generate
# 阶段2:打包Next standalone
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# 阶段3:纯运行镜像,只拷贝运行必需文件,舍弃完整prisma CLI
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
# Next standalone 运行文件
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# 仅复制 prisma schema + 生成好的client(不需要完整CLI、wasm
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma/client ./node_modules/@prisma/client
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app /app/data
USER nextjs
EXPOSE 3000
# 运行时不再执行 npx prisma,直接启动服务
CMD ["node", "server.js"]