Docker 打包部署vue

1、先打包后端服务,我们采用的是nginx 服务部署vue  新建Dockerfile

目录如下

Docker 打包部署vue_第1张图片

2、编写Dockerfile

# 设置基础镜像 
FROM nginx:alpine
# 定义作者
MAINTAINER test
# 将dist文件中的内容复制到 /etc/nginx/html/ 这个目录下面
COPY dist/  /etc/nginx/html/
# 将配置文件中的内容复制到 /etc/nginx 这个目录下面(增加自己的代理及一些配置)
RUN rm -rf /etc/nginx/nginx.conf 
COPY nginx.conf /etc/nginx/nginx.conf

nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

	server {
		listen       80;
		listen  [::]:80;
		server_name  localhost;
		location / {
			root   /etc/nginx/html;
			index  index.html index.htm;
		}
		location = /50x.html {
			root   /usr/share/nginx/html;
		}
		
	}
}


 

3、编写快速构建的脚本buildDocker.bat

::打包镜像
docker build -t reg.htres.cn/yw_18kn1/demonginx .

::推镜像
docker push reg.htres.cn/yw_18kn1/demonginx

::展示镜像
docker images

pause

4、启动

docker run -p 80:80 -d reg.htres.cn/yw_18kn1/demonginx

 

你可能感兴趣的:(打包部署,Docker)