Dockerfile 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # 使用官方 Node.js 作为基础镜像;不适用 alpine 版本,这样可以自带git
  2. FROM node:latest AS builder
  3. # 在容器中创建目录
  4. WORKDIR /app
  5. # 安装pnpm
  6. RUN npm install -g pnpm@10.10.0
  7. # 设置pnpm镜像源
  8. RUN pnpm config set registry https://registry.npmmirror.com
  9. # 复制依赖文件
  10. COPY package.json pnpm-lock.yaml ./
  11. # 先复制scripts目录,因为prepare脚本需要用到其中的文件
  12. COPY scripts ./scripts
  13. # 创建src目录,确保create-base-files.js脚本能正常写入文件
  14. RUN mkdir -p src
  15. # 安装依赖
  16. RUN pnpm install
  17. # 复制其余源代码
  18. COPY . .
  19. # 构建项目
  20. RUN pnpm run build
  21. # 使用nginx作为服务
  22. FROM nginx:1.29.1-alpine3.22 AS production-stage
  23. # 将构建好的项目复制到nginx下
  24. COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
  25. # 将默认的nginx配置文件替换为我们自定义的nginx配置文件
  26. COPY nginx.conf /etc/nginx/conf.d/default.conf
  27. # 暴露端口
  28. EXPOSE 80
  29. EXPOSE 443
  30. # 启动nginx
  31. CMD ["nginx", "-g", "daemon off;"]