当前位置: 首页 > news >正文

Docker(Nginx)部署Vue

简介:目标使用docker将vue生成的dist文件,结合nginx生成镜像,然后运行;

1、首选确保vue项目正确运行,并能正确打包dist文件;
第一个是运行命令,第二个是打包命令
2、查看已经生成的dist文件
在这里插入图片描述
3、将dist文件打包为rar文件或者zip文件,本文使用rar文件
在这里插入图片描述
4、确保服务器已经安装docker;
新建文件夹:/home/questionaire-app/
将dist.rar 上传到该目录下,并解压到当前目录下;

unrar x dist.rar

5、在/home/questionaire-app/下新建nginx配置文件default.conf,新建Dockerfile文件;
1)编辑default.conf文件

server {listen       80;server_name  127.0.0.1;#charset koi8-r;#access_log  /var/log/nginx/log/host.access.log  main;location / {root   /usr/share/nginx/html;try_files $uri $uri/ /index.htmlindex  index.html index.htm;}location /prod-api/ {proxy_pass  http://127.0.0.1:18080/;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
}

代理可以根据需求配置,不强求
在这里插入图片描述

2)编辑Dockerfile文件:

# 使用nginx镜像
FROM nginx
# 作者
MAINTAINER cmh
# 删除nginx 默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 添加我们自己的配置 default.conf 在下面
ADD default.conf /etc/nginx/conf.d/
# 把刚才生成dist文件夹下的文件copy到nginx下面去
COPY dist/  /usr/share/nginx/html/

最终该目录下是这样的:
在这里插入图片描述

6、生成镜像并运行

1)生成镜像
“ . ” 这个点不要省略

docker build -t mall-admin-vue .

在这里插入图片描述
2)运行容器

docker run -d --name mall-admin-vue -p 8088:80 mall-admin-vue

7、测试:
浏览器通过ip+端口访问
在这里插入图片描述
参考文档:https://blog.csdn.net/cmh1008611/article/details/144793141

http://www.lryc.cn/news/542420.html

相关文章:

  • ubuntu22.04的docker容器中安装ssh服务
  • 卷积这个词在卷积神经网络中应该怎么理解
  • 设计模式教程:迭代器模式(Iterator Pattern)
  • C语言学习【1】C语言关于寄存器的封装
  • 鸿蒙app 开发中的 == 和 === 的区别
  • 【算法】冒泡排序
  • R Excel 文件:高效数据处理的利器
  • 数据库(MySQL):使用命令从零开始在Navicat创建一个数据库及其数据表(一).创建基础表
  • 电力通信物联网应用,国密网关守护电力数据安全
  • vue:vite 代理服务器 proxy 配置
  • Java【网络原理】(2)初识网络续与网络编程
  • AI+集装箱号码识别技术,主要发展方向和应用潜力
  • 安装可视化jar包部署平台JarManage
  • 后端之JPA(EntityGraph+JsonView)
  • Java数据结构第十三期:走进二叉树的奇妙世界(二)
  • JavaScript系列(86)--现代构建工具详解
  • docker容器网络配置及常用操作
  • Docker 性能优化指南
  • 课程1. 深度学习简介
  • 【cuda学习日记】4.3 结构体数组与数组结构体
  • 2025最新高维多目标优化:基于城市场景下无人机三维路径规划的导航变量的多目标粒子群优化算法(NMOPSO),MATLAB代码
  • 数字IC后端设计实现OCC(On-chip Clock Controller)电路介绍及时钟树综合案例
  • Linux内核,slub分配流程
  • 本地部署DeepSeek-R1(Ollama+Docker+OpenWebUI知识库)
  • Java 实现快速排序算法:一条快速通道,分而治之
  • 20250223下载并制作RTX2080Ti显卡的显存的测试工具mats
  • element-ui的组件使用
  • 医疗AI领域中GPU集群训练的关键技术与实践经验探究(上)
  • 详解Redis淘汰策略
  • HarmonyOS 5.0应用开发——鸿蒙接入高德地图实现POI搜索