前面说明了服务器Nginx的安装和配置,这里稍微有些不同,但是因为此文是用Nginx镜像和前端镜像页面同时部署的方式来打包发布的,所以这里不再需要建立
/data/container/nginx/html目录,因为要发布的静态页面已经在Nginx镜像中的/nginx/html目录了。这里也减少了手动部署安装Nginx的步骤,而是在Jenkins任务中调用shell命令自动执行安装。
FROM nginx:latest# 维护者信息MAINTAINER gitegg# 将生成的静态页面文件复制到nginx的/usr/share/nginx/html/目录COPY dist/ /usr/share/nginx/html/# 容器启动时运行的命令CMD ["nginx", "-g", "daemon off;"]
mkdir -p /opt/tmp /opt/bak /opt/script /data/container/nginx/www /data/container/nginx/logs /data/container/nginx/etcchmod -R 777 /opt/tmp /opt/bak /opt/script /data/container/nginx/www /data/container/nginx/logs /data/container/nginx/etc
server { listen 80; server_name 域名; gzip on; gzip_buffers 32 4K; gzip_comp_level 6; gzip_min_length 100; gzip_types application/javascript text/css text/xml text/plain application/x-javascript image/jpeg image/gif image/png; gzip_disable "MSIE [1-6]/."; gzip_vary on; #charset koi8-r; access_log /var/log/nginx/portal.access.log main; location / { root /nginx/html/gitegg_portal; try_files $uri $uri/ /index.html; index index.html index.htm; } location /gitegg-api/ { proxy_set_header Host $http_host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.17.0.1:8080/; } }
echo "param validate"if [ $# -lt 1 ]; then echo "you must use like this : ./publish_docker_portal.sh <container_name> <image_name> <version> [portal port] [server port] [portal ssl port] [server ssl port]" exit fi
if [ "$1" != "" ]; then container_name="$1"fiecho "container_name=" $container_nameif [ "$2" != "" ]; then image_name="$2"fiif [ "$3" != "" ]; then version="$3"fiecho "version=" $versionif [ "$4" != "" ]; then portal_port="$4"fiecho "portal_port=" $portal_portif [ "$5" != "" ]; then server_port="$5"fiecho "server_port=" $server_portif [ "$6" != "" ]; then portal_ssl_port="$6"fiecho "portal_ssl_port=" $portal_ssl_portif [ "$7" != "" ]; then serve_sslr_port="$7"fiecho "serve_sslr_port=" $serve_sslr_port
echo "执行docker ps"docker ps if [[ "$(docker inspect $container_name 2> /dev/null | grep $container_name)" != "" ]]; then echo $container_name "容器存在,停止并删除" echo "docker stop" $container_name docker stop $container_name echo "docker rm" $container_name docker rm $container_nameelse echo $container_name "容器不存在"fi
# 删除镜像echo "执行docker images"docker imagesif [[ "$(docker images -q $image_name 2> /dev/null)" != "" ]]; then echo $image_name '镜像存在,删除镜像' docker rmi $(docker images -q $image_name 2> /dev/null) --forceelse echo $image_name '镜像不存在'fi
#bak imageecho "bak image" $image_nameBAK_DIR=/opt/bak/docker/$image_name/`date +%Y%m%d`mkdir -p "$BAK_DIR"cp "/opt/tmp/portal-image.tar" "$BAK_DIR"/"$image_name"_`date +%H%M%S`.tar
echo "docker load" $image_namedocker load --input /opt/tmp/portal-image.tar
echo "docker run" $image_namedocker run -d -p $portal_port:$server_port -p $portal_ssl_port:$server_ssl_port --name=$container_name -e TZ="Asia/Shanghai" --restart=always -v /data/container/nginx/www:/var/www -v /data/container/nginx/logs:/var/log/nginx -v /data/container/nginx/etc:/etc/nginx -v /data/container/nginx/etc/nginx.conf:/etc/nginx/nginx.conf -v /etc/localtime:/etc/localtime -v /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone -v /bxl/container/nginx/ssl:/nginx/ssl $image_name
echo "remove tmp " $image_namerm -rf /opt/tmp/portal-image.tar
echo "Docker Portal is starting,please try to access $container_name conslone url"
container_name=portal-serverimage_name=portal-serverversion=latestportal_port=80server_port=80portal_ssl_port=443serve_sslr_port=443echo "param validate"if [ $# -lt 1 ]; then echo "you must use like this : ./publish_docker_portal.sh <container_name> <image_name> <version> [portal port] [server port] [portal ssl port] [server ssl port]" exit fiif [ "$1" != "" ]; then container_name="$1"fiecho "container_name=" $container_nameif [ "$2" != "" ]; then image_name="$2"fiif [ "$3" != "" ]; then version="$3"fiecho "version=" $versionif [ "$4" != "" ]; then portal_port="$4"fiecho "portal_port=" $portal_portif [ "$5" != "" ]; then server_port="$5"fiecho "server_port=" $server_portif [ "$6" != "" ]; then portal_ssl_port="$6"fiecho "portal_ssl_port=" $portal_ssl_portif [ "$7" != "" ]; then serve_sslr_port="$7"fiecho "serve_sslr_port=" $serve_sslr_portecho "执行docker ps"docker ps if [[ "$(docker inspect $container_name 2> /dev/null | grep $container_name)" != "" ]]; then echo $container_name "容器存在,停止并删除" echo "docker stop" $container_name docker stop $container_name echo "docker rm" $container_name docker rm $container_nameelse echo $container_name "容器不存在"fi# 删除镜像echo "执行docker images"docker imagesif [[ "$(docker images -q $image_name 2> /dev/null)" != "" ]]; then echo $image_name '镜像存在,删除镜像' docker rmi $(docker images -q $image_name 2> /dev/null) --forceelse echo $image_name '镜像不存在'fi#bak imageecho "bak image" $image_nameBAK_DIR=/opt/bak/docker/$image_name/`date +%Y%m%d`mkdir -p "$BAK_DIR"cp "/opt/tmp/portal-image.tar" "$BAK_DIR"/"$image_name"_`date +%H%M%S`.tarecho "docker load" $image_namedocker load --input /opt/tmp/portal-image.tarecho "docker run" $image_namedocker run -d -p $portal_port:$server_port -p $portal_ssl_port:$server_ssl_port --name=$container_name -e TZ="Asia/Shanghai" --restart=always -v /data/container/nginx/www:/var/www -v /data/container/nginx/logs:/var/log/nginx -v /data/container/nginx/etc:/etc/nginx -v /data/container/nginx/etc/nginx.conf:/etc/nginx/nginx.conf -v /etc/localtime:/etc/localtime -v /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone -v /bxl/container/nginx/ssl:/nginx/ssl $image_nameecho "remove tmp " $image_namerm -rf /opt/tmp/portal-image.tarecho "Docker Portal is starting,please try to access $container_name conslone url"
本文链接://www.dmpip.com//www.dmpip.com/showinfo-26-10462-0.html【微服务部署】Jenkins+Docker一键打包部署Vue项目步骤详解
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。邮件:2376512515@qq.com
上一篇: 我们一起聊聊.NET 8 RC1