First commit
This commit is contained in:
29
frontend/Dockerfile
Normal file
29
frontend/Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# =====================================================================
|
||||
# 前端镜像: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
|
||||
Reference in New Issue
Block a user