# 构建阶段 FROM node:18-alpine AS builder WORKDIR /build # 复制 package 文件和 npm 配置 COPY package*.json ./ COPY .npmrc ./ # 安装依赖(.npmrc 中已配置私有 registry 和认证) RUN npm install # 复制源码 COPY . . # 构建生产版本 RUN npm run build # 运行阶段:使用 Nginx 服务静态文件 FROM nginx:alpine LABEL maintainer="JohnSion" LABEL description="武术比赛管理系统前端" # 复制构建产物到 Nginx 目录 COPY --from=builder /build/dist /usr/share/nginx/html # 复制 Nginx 配置 COPY nginx.conf /etc/nginx/conf.d/default.conf # 暴露端口 EXPOSE 80 # 健康检查 HEALTHCHECK --interval=30s --timeout=3s CMD wget -q --spider http://localhost/ || exit 1 # 启动 Nginx CMD ["nginx", "-g", "daemon off;"]