Files
wecom-ai-assistant/deploy/docker/admin.Dockerfile
2026-02-05 16:36:32 +08:00

53 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.
# 生产环境 Admin Dockerfile最小构建
# 用途:构建优化的 Next.js 生产镜像
FROM node:20-alpine AS builder
WORKDIR /app
# 设置 npm 镜像(可选,根据网络情况)
ARG NPM_REGISTRY=https://registry.npmjs.org
RUN npm config set registry ${NPM_REGISTRY}
# 复制依赖文件
COPY admin/package.json admin/package-lock.json* ./
# 安装依赖
RUN npm ci --legacy-peer-deps --only=production
# 复制源代码
COPY admin/ .
# 构建 Next.js 应用
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# 生产镜像
FROM node:20-alpine
WORKDIR /app
# 从 builder 复制构建产物
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# 设置环境变量
ENV NODE_ENV=production
ENV PORT=3000
ENV NEXT_TELEMETRY_DISABLED=1
# 创建非 root 用户
RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001 && \
chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" || exit 1
CMD ["node", "server.js"]