SunnyFarm/frontend/Dockerfile
2026-02-28 07:15:26 +08:00

37 lines
934 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.

# ============================================
# 农产品直销平台 - 前端 Dockerfile
# 多阶段构建: Node编译 → Nginx部署
# ============================================
# ---------- 第一阶段Node构建 ----------
FROM node:18-alpine AS builder
WORKDIR /app
# 配置npm镜像加速依赖下载
RUN npm config set registry https://registry.npmmirror.com
# 先复制package文件利用Docker缓存层
COPY package*.json ./
RUN npm install
# 复制源代码并构建
COPY . .
RUN npm run build
# ---------- 第二阶段Nginx部署 ----------
FROM nginx:1.25-alpine
# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 复制自定义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;"]