# Frontend Dockerfile - Multi-stage build FROM node:18-alpine AS builder # 设置工作目录 WORKDIR /app # 复制 package 文件 COPY package*.json ./ # 安装依赖 RUN npm ci # 复制源代码 COPY . . # 构建生产版本 RUN npm run build # 生产镜像 - 使用 nginx FROM nginx:alpine # 复制构建产物 COPY --from=builder /app/dist /usr/share/nginx/html # 复制 nginx 配置 COPY nginx.conf /etc/nginx/conf.d/default.conf # 暴露端口 EXPOSE 80 # 健康检查 HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1 # 启动 nginx CMD ["nginx", "-g", "daemon off;"]