Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # 设置基础镜像
  2. FROM node:21.7.3-alpine3.20 as build-stage
  3. # 定义作者
  4. LABEL maintainer=Zenas
  5. #创建一个工作目录
  6. WORKDIR /app
  7. # 复制package.json文件和package-lock.json文件到容器工作目录
  8. COPY . /app
  9. # 安装项目依赖
  10. RUN yarn install
  11. # 构建前端项目
  12. RUN yarn build
  13. # production stage
  14. FROM nginx as production-stage
  15. #COPY --from=build-stage ./dist /usr/share/nginx/html
  16. RUN echo "server { \
  17. listen 80; \
  18. location /shop-api/ { \
  19. proxy_pass http://69.230.201.115:8080/shop-api/; \
  20. proxy_redirect off; \
  21. proxy_set_header Host http://69.230.201.115:8080; \
  22. proxy_set_header X-Real-IP \$remote_addr; \
  23. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; \
  24. } \
  25. #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 \
  26. location / { \
  27. root /var/www/html/; \
  28. index index.html index.htm; \
  29. if (!-e \$request_filename) { \
  30. rewrite ^(.*)\$ /index.html?s=\$1 last; \
  31. break; \
  32. } \
  33. } \
  34. access_log /var/log/nginx/access.log ; \
  35. } " > /etc/nginx/conf.d/default.conf \
  36. && mkdir -p /var/www \
  37. && mkdir -p /var/www/html
  38. ADD /app/dist/ /var/www/html/
  39. # 暴露镜像端口
  40. EXPOSE 80
  41. EXPOSE 443
  42. CMD ["nginx","-g","daemon off"]