Docker部署vue项目

Centos7环境下安装docker,亦可ubantu\windos\mac只是dicker安装的命令不同可自行安装,这里不做介绍

——第一步安装docker 有则忽略

# 1、yum 包更新到最新 
yum update
# 2、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的 
yum install -y yum-utils device-mapper-persistent-data lvm2
# 3、 设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 4、 安装docker,出现输入的界面都按 y 
yum install -y docker-ce
# 5、 查看docker版本,验证是否验证成功
docker -v

——第二步将vue项目放入服务器任意位置
1,在本地创建docker-vue文件夹,将打包好的dist文件夹放入gocker-vue
2,在docker-vue文件夹中新建文本文档为dockerfile.txt,并在文档中写入如下内容

FROM nginx:latest
MAINTAINER xxh
COPY dist/ /usr/share/nginx/html/

在docker-vue文件夹中新建nginx.conf 并写入以下内容

worker_processes auto;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    client_max_body_size   20m;
    server {
        listen       80;
        server_name  xxh;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
     location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
        }
        #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;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
}

3,将docker-vue上传至服务器任意目录,将dockerfile.txt重命名为dockerfile.
4.通过Xshell等工具进入到服务器docker-vue文件夹下

[root@iz2zeeln8k6ea70n7a49erz docker-vue]#

输入如下命令

docker build -t gentle-vue .

5.启动容器

docker run -p 80:80 -d --name gentle-vue gentle-vue

6.浏览器访问服务器地址即可

删除容器
先列出有哪些容器(列出所有的):docker ps -a
显示所有容器:docker ps -a
只显示容器ID:docker ps -q
要先暂停容器,才能删除:
暂停所有容器:docker stop (docker ps -aq) 暂停单个容器:docker stop < CONTAINER ID > 删除容器: 删除所有容器:docker rm(docker ps -aq)
删除单个容器:docker rm < CONTAINER ID >
强制删除 -f, --force:docker rm -f < CONTAINER ID >
删除指定链接-l, --link:docker rm -l < CONTAINER ID >
删除容器关联数据卷-v --volumes:docker rm -v < CONTAINER ID >
删除镜像
列出镜像:docker images
删除镜像:
删除单个镜像:docker rmi < IMAGE ID >
删除所有镜像:docker rmi (docker images -q) 遇见关联镜像删除不了时,强制删除:docker rmi -f(docker images -q)
注:不明白的命令使用 --help查询

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容