feat: 添加前端 Dockerfile 和 Nginx 配置

- 多阶段构建:node:22-alpine 构建,nginx:stable-alpine 运行
- Nginx 配置:静态文件服务 + /api /ws 反代到后端
This commit is contained in:
hhs
2026-06-14 13:38:22 +08:00
parent 80e45bb8ff
commit 7108d2a58b
2 changed files with 71 additions and 0 deletions

25
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
# ---- 构建阶段 ----
FROM node:22-alpine AS builder
WORKDIR /app
# 先复制依赖清单,利用 Docker 缓存层
COPY package.json package-lock.json ./
RUN npm ci
# 复制源码并构建
COPY . .
RUN npm run build
# ---- 运行阶段 ----
FROM nginx:stable-alpine
# 复制 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]