Dockerfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # 使用 Node 镜像构建 Vue 项目
  2. FROM node:20-alpine AS build-stage
  3. # 设置工作目录
  4. WORKDIR /app
  5. # 复制项目文件
  6. COPY . .
  7. RUN npm install -g pnpm
  8. RUN pnpm config set registry https://registry.npmmirror.com
  9. RUN cd ${WORKDIR}
  10. # -----------------------------------------------------------------
  11. # 【核弹级修复】
  12. # 既然本地和线上不一致,我们直接在 Docker 里“销毁”旧锁文件!
  13. # 这样 pnpm install 就会被迫重新读取 package.json。
  14. # 因为我们在 package.json 里写了 overrides: "2.4.2",
  15. # 所以它这次一定会乖乖下载 2.4.2,绝对不会再去下 2.6.1 了。
  16. # -----------------------------------------------------------------
  17. RUN rm -f pnpm-lock.yaml
  18. # 重新安装依赖(不使用锁文件,完全依赖 package.json 的 overrides)
  19. RUN pnpm install
  20. # 构建生产环境静态文件
  21. RUN pnpm run build-web
  22. RUN pnpm run build-backend-html
  23. # 使用 Nginx 镜像作为运行时
  24. FROM nginx:alpine
  25. # 复制 Nginx 配置文件
  26. COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
  27. # 从构建阶段复制静态文件到 Nginx 的默认静态文件目录
  28. COPY --from=build-stage /app/packages/web/dist /usr/share/nginx/html
  29. COPY --from=build-stage /app/packages/frontend/dist /usr/share/nginx/html/admin
  30. # 暴露 80 端口
  31. EXPOSE 80
  32. # 启动 Nginx
  33. CMD ["nginx", "-g", "daemon off;"]