Files
Edu/apps/teacher-portal/Dockerfile
SpecialX 4a0893ef52 feat(infra): 新增生产 Dockerfile 与部署 compose
- api-gateway/Dockerfile: 多阶段构建,golang:1.22-alpine → alpine:3.20,CGO_ENABLED=0 静态编译,非 root 运行

- teacher-portal/Dockerfile: 多阶段构建,node:20-alpine builder → runner,含 HEALTHCHECK

- docker-compose.prod.yml: 本地生产编排,3 服务,强制 DEV_MODE=false

- docker-compose.deploy.yml: 服务器部署用,镜像来自 Gitea Registry,通过 edu-shared 外部网络连接 MySQL/Redis

- deploy.env.example: 部署环境变量模板
2026-07-08 15:12:34 +08:00

50 lines
1.6 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.
# 多阶段构建Next.js 生产镜像
# 用法docker build -t edu/teacher-portal:latest -f apps/teacher-portal/Dockerfile .
# ============ Builder ============
FROM node:20-alpine AS builder
WORKDIR /app
# 启用 pnpm
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
# 先拷依赖清单,利用缓存
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
COPY apps/teacher-portal/package.json ./apps/teacher-portal/
# 安装依赖(含 devDependencies构建需要
RUN pnpm install --filter @edu/teacher-portal... --frozen-lockfile || pnpm install --filter @edu/teacher-portal...
# 拷源码
COPY apps/teacher-portal ./apps/teacher-portal
# 构建(禁用 telemetry生产模式
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm --filter @edu/teacher-portal run build
# ============ Runtime ============
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
# 非 root 用户运行
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
# 拷构建产物与必要清单
COPY --from=builder /app/apps/teacher-portal/package.json ./package.json
COPY --from=builder /app/apps/teacher-portal/.next ./.next
COPY --from=builder /app/apps/teacher-portal/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/apps/teacher-portal/next.config.js ./next.config.js
USER nextjs
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD wget --quiet --spider http://localhost:3000/ || exit 1
CMD ["node_modules/.bin/next", "start", "-p", "3000"]