Files
lab/frontend/Dockerfile
2026-09-21 12:51:08 +08:00

30 lines
926 B
Docker
Raw 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.
# =====================================================================
# 前端镜像:pnpm 构建静态资源 -> Nginx 托管(同时反代 /api 到后端)
# 构建:docker build -t lab-frontend ./frontend
# =====================================================================
# ---------- 构建阶段 ----------
FROM node:24-alpine AS build
WORKDIR /app
# 使用与本地一致的 pnpm 主版本,锁定依赖保证可复现
RUN npm install -g pnpm@11.3.0
# 先装依赖,充分利用层缓存
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
# ---------- 运行阶段 ----------
FROM nginx:1.27-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
HEALTHCHECK --interval=15s --timeout=3s --start-period=10s --retries=3 \
CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1