40 lines
1.0 KiB
Docker
40 lines
1.0 KiB
Docker
# ============================================================
|
|||
|
|
# 多阶段构建 (开发机有网络时使用)
|
||
|
|
# docker build -t weather-data-ui .
|
||
|
|
# ============================================================
|
||
|
|
FROM node:20-alpine AS builder
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# 安装依赖
|
||
|
|
COPY package.json package-lock.json* ./
|
||
|
|
RUN npm ci --registry=https://registry.npmmirror.com
|
||
|
|
|
||
|
|
# 复制源码并构建
|
||
|
|
COPY . .
|
||
|
|
RUN npm run build:prod
|
||
|
|
|
||
|
|
# ============================================================
|
||
|
|
# 运行阶段 - Nginx 提供静态文件服务
|
||
|
|
# ============================================================
|
||
|
|
FROM nginx:alpine
|
||
|
|
|
||
|
|
LABEL maintainer="weather-data"
|
||
|
|
LABEL description="Weather Data System - Frontend UI"
|
||
|
|
|
||
|
|
# 删除默认配置
|
||
|
|
RUN rm -f /etc/nginx/conf.d/default.conf
|
||
|
|
|
||
|
|
# 复制自定义 nginx 配置
|
||
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||
|
|
|
||
|
|
# 复制构建产物
|
||
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||
|
|
|
||
|
|
EXPOSE 80
|
||
|
|
|
||
|
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
||
|
|
CMD wget -qO- http://localhost/ || exit 1
|
||
|
|
|
||
|
|
CMD ["nginx", "-g", "daemon off;"]
|