Dockerfile 848 B

12345678910111213141516171819202122232425262728293031323334353637
  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. # 安装依赖
  14. RUN pnpm install
  15. # 复制其余源代码
  16. COPY . .
  17. # 构建项目
  18. RUN pnpm run build
  19. # 使用nginx作为服务
  20. FROM nginx:1.29.1-alpine3.22 AS production-stage
  21. # 将构建好的项目复制到nginx下
  22. COPY --from=builder /app/dist/build/h5 /usr/share/nginx/html
  23. COPY nginx.conf /etc/nginx/nginx.conf
  24. # 暴露端口
  25. EXPOSE 80
  26. EXPOSE 443
  27. # 启动nginx
  28. CMD ["nginx", "-g", "daemon off;"]