# 構建階段 FROM node:18-alpine as build WORKDIR /app # 複製package文件 COPY package*.json ./ # 安裝依賴 RUN npm ci # 複製源代碼 COPY . . # 構建應用 RUN npm run build # 生產階段 FROM nginx:alpine # 複製構建結果 COPY --from=build /app/dist /usr/share/nginx/html # 複製nginx配置 COPY nginx.conf /etc/nginx/conf.d/default.conf # 暴露端口 EXPOSE 3000 # 健康檢查 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3000 || exit 1 # 啟動nginx CMD ["nginx", "-g", "daemon off;"]