anxin-ruoyi/docker/frontend/Dockerfile
2026-01-08 20:47:24 +08:00

46 lines
996 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 for 若依 Vue3 前端应用
# 第一阶段:构建阶段
FROM node:18-alpine AS build-stage
# 设置工作目录
WORKDIR /app
# 复制 package.json 和 package-lock.json如果存在
COPY RuoYi-Vue3/package*.json ./
# 安装依赖
RUN npm install --registry=https://registry.npmmirror.com
# 复制源代码
COPY RuoYi-Vue3/ .
# 构建应用
RUN npm run build:prod
# 第二阶段:运行阶段
FROM nginx:alpine AS production-stage
# 定义构建参数
ARG ENVIRONMENT=development
# 安装 tzdata 用于时区设置
RUN apk add --no-cache tzdata
# 设置时区
ENV TZ=Asia/Shanghai
# 从构建阶段复制构建产物到 nginx 默认目录
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 根据环境复制对应的 nginx 配置文件
COPY docker/configs/nginx.conf.${ENVIRONMENT} /etc/nginx/conf.d/default.conf
# 创建日志目录
RUN mkdir -p /var/log/nginx
# 暴露端口
EXPOSE 80
# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]