Files
2026-09-03 11:56:49 +08:00

33 lines
978 B
Docker
Raw Permalink 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.
# ── Stage 1: Build ──────────────────────────────────
FROM node:20-alpine AS builder
WORKDIR /app
# 先复制依赖描述文件,利用 Docker 缓存层
COPY package.json package-lock.json* ./
# 安装依赖
RUN npm install --registry=https://registry.npmmirror.com
# 复制源码
COPY . .
# 构建生产包(tsc + vite build → dist/)
RUN npm run build
# ── Stage 2: Serve ──────────────────────────────────
FROM nginx:alpine
# 将构建产物复制到 Nginx 默认静态目录
COPY --from=builder /app/dist /usr/share/nginx/html
# Nginx 配置模板(支持 envsubst 环境变量替换)
COPY nginx.conf /etc/nginx/templates/default.conf.template
# 默认后端 API 地址(运行时可通过 -e BACKEND_URL=... 覆盖)
ENV BACKEND_URL=http://10.100.154.100:8000
EXPOSE 8901
CMD ["nginx", "-g", "daemon off;"]