docker+nginx部署vue项目

环境

  • Centos 7
  • Docker
  • Nginx

将项目打包

yarn run build

打包生成生成dist静态资源目录

 
docker+nginx部署vue项目_第1张图片
 

 

我这里资源文件放置在阿里云服务器/usr/gaolei/dockers/nginx-docker

 
15668934-4bcf7aed79fe9727
 
 
15668934-692b646099736c43
 

编写Dockerfile

vim Dockefile
 
docker+nginx部署vue项目_第2张图片
 
# Base Image设置基础镜像
FROM nginx

#Define Author 定义作者
# maintainer [已遗弃]
# MAINTAINER DuebassLei [email protected]
LABEL maintaniner="DuebassLei"

# 将文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面
COPY vueAdmin/  /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf

编辑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  127.0.0.1;
 
        #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;
    #    }
    #}
}

构建自定义镜像

# 默认使用当前目录下的Dockerfile构建
docker build -t nginx:v1 .
 
docker+nginx部署vue项目_第3张图片
 

查看镜像

docker images
 
15668934-e859de325a2b7c93
 

启动并查看运行容器

# -p 端口转发 宿主机端口:容器端口  
docker run -p 9999:80 -d nginx:v1
docker ps
 
15668934-25d8dc656a5a11b3
 

访问效果

 
docker+nginx部署vue项目_第4张图片
 

你可能感兴趣的:(Docker,Vue,Linux,docker)