首页 > 其他分享 >vue 部署docker容器

vue 部署docker容器

时间:2022-11-03 09:34:25浏览次数:50  
标签:容器 vue dist index nginx html location docker

1、修改 vue.config.js 配置文件

若没有这个配置文件,就在项目根目录新建一个,增加以下配置:

module.exports = {
    # 生产环境是否要生成 sourceMap
    productionSourceMap: false,
    # 这个值也可以被设置为空字符串 (’’) 或是相对路径 (’./’),这样所有的资源都会被链接为相对路径,这样打出来的包可以被部署在任意路径。
    publicPath: './',
    # 输出文件目录
    outputDir: 'dist',
    # 放置静态文件夹目录
    # assetsDir: 'assets',
    ......
}

 

2、构建 vue 项目

使用命令 npm run build 来打包项目,打包的文件根据配置存放在 dist 目录 

 

 

 3、构建 docker 镜像

我们这里用 vue + nginx 的方式部署到 docker。将 dist、Dockerfile、default.conf 放置在 linux 服务器的同一目录

Dockerfile文件:

FROM nginx:1.17

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone

COPY dist/  /usr/share/nginx/html/

COPY default.conf  /etc/nginx/conf.d/

 

 default.conf 文件,按需修改:

server {
    listen       8000;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/dist;
        index  index.html index.htm;
    }

    #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   /usr/share/nginx/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;
    #}
}

 

使用命令 docker build -t vueproject . 构建docker镜像

 

 4、运行容器

启动容器,运行刚才构建的镜像。docker run -it -d -p 7000:8000 -v /home/docker/testproject:/usr/share/nginx/html --name vueproject --restart always --privileged=true vueproject

 访问地址:http://127.0.0.1:8000

 

标签:容器,vue,dist,index,nginx,html,location,docker
From: https://www.cnblogs.com/shenh/p/16825642.html

相关文章

  • Docker安装Oracle(简单,好用)
    Docker安装Oracle(以Oracle_11g为例)拉取oracle_11g镜像:dockerpullregistry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g运行容器1dockerrun-d-p1521:1521-......
  • Docker 常用命令
    参考地址查看docker网络$dockernetworklsNETWORKIDNAMEDRIVERSCOPE7fca4eb8c647bridgebridge......
  • vue富文本编辑器
    Vue-Quill-Editor主流富文本编辑器对比前言:vue中很多项目都需要用到富文本编辑器,在使用了ueditor和tinymce后,发现并不理想。所以果断使用vue-quill-editor来实现。wan......
  • PyCharm配置远程Docker环境
    1.docker配置使用-p参数暴露一个端口用于ssh连接。dockerrun-itd--namewangchao_paddle--gpusall-p8899:8888-p8822:22-v/data:/root/dataregistry.bai......
  • vue路由页面跳转
    import{useRouter}from'vue-router';exportdefault{setup(){const$router=useRouter();//点击方法functiongo(){$rou......
  • 20_Vue如何监测数组类型数据发生改变的?
    通过上一节,我们知道了vue检测对象数据发生改变的原理但是还有个api我们没有讲解,Vue.set();这个API比较适合在理解了对象检测的原理后进行讲解案例准备html<!--创建一......
  • vuex中能直接修改state吗?
    当我们使用vuex的时候,时不时能看到“更改Vuex中的store中的状态唯一办法就是提交mutations”,但是有没有试想过,我们不提交mutations其实也能修改state的值?答案是可以的我们......
  • Vue项目中定时器的问题...
    Vue项目中定时器的问题...比如说我们现在在a页面写一个定时,让他每秒钟处理操作,比如:每秒钟打印一个1,然后跳转到b页面,此时可以看到,定时器依然在执行。这样是非常消耗性能的......
  • vue导入项目缺少依赖‘node_modules’
    从git下载好的项目,导入vue时提示‘node_modules’依赖则需要在你的项目包下面找是否有package-lock.json文件,如:如果有,但是依旧报错,直接删除package-lock.json文件,用终......
  • vue实现小汽车功能
    查看代码<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><me......