2020年5月23日 | Leave a comment 问题 解决: 使用 ./deploy.sh a@a.com root@b.com deploy.sh : #!/bin/bash # 用于将 docker 镜像发布到多台服务器 #./deploy.sh a@a.com root@b.com TAG=$(date +"v%Y%m%d%H%M%S") build() { #export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1104_j9/Contents/Home mvn -verbose mvn -DskipTests=true clean package #git tag $TAG docker build -f Dockerfile -t np/app-a:$TAG . #推送到 aliyun docker 仓库 docker login --username='ssss' -p 'bbbb' registry.cn-shanghai.aliyuncs.com docker tag np/app-a:$TAG registry.cn-shanghai.aliyuncs.com/np/app-a:$TAG docker push registry.cn-shanghai.aliyuncs.com/np/app-a:$TAG } killss() { SITE=$1 PSAUX=$(ssh $SITE docker ps | grep -i app-a | grep -v bash | tail -n 1) #echo $PSAUX while test "$PSAUX"; do CID=$(echo $PSAUX | awk 'RS {print $1 }') echo "kill $CID" ssh $SITE "docker kill $CID" PSAUX=$(ssh $SITE docker ps | grep -i app-a | grep -v bash | tail -n 1) done } upload() { SITE=$1 echo $SITE echo " update docker on $SITE" killss $SITE ssh $SITE "docker run -d --restart=on-failure egistry.cn-shanghai.aliyuncs.com/np/app-a:$TAG" echo "更新成功 $SITE $TAG" } build for i in $@; do upload "$i" done 123456789101112131415161718192021222324252627282930313233343536373839404142 #!/bin/bash# 用于将 docker 镜像发布到多台服务器 #./deploy.sh a@a.com root@b.com TAG=$(date +"v%Y%m%d%H%M%S")build() { #export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1104_j9/Contents/Home mvn -verbose mvn -DskipTests=true clean package #git tag $TAG docker build -f Dockerfile -t np/app-a:$TAG .#推送到 aliyun docker 仓库 docker login --username='ssss' -p 'bbbb' registry.cn-shanghai.aliyuncs.com docker tag np/app-a:$TAG registry.cn-shanghai.aliyuncs.com/np/app-a:$TAG docker push registry.cn-shanghai.aliyuncs.com/np/app-a:$TAG}killss() { SITE=$1 PSAUX=$(ssh $SITE docker ps | grep -i app-a | grep -v bash | tail -n 1) #echo $PSAUX while test "$PSAUX"; do CID=$(echo $PSAUX | awk 'RS {print $1 }') echo "kill $CID" ssh $SITE "docker kill $CID" PSAUX=$(ssh $SITE docker ps | grep -i app-a | grep -v bash | tail -n 1) done}upload() { SITE=$1 echo $SITE echo " update docker on $SITE" killss $SITE ssh $SITE "docker run -d --restart=on-failure egistry.cn-shanghai.aliyuncs.com/np/app-a:$TAG" echo "更新成功 $SITE $TAG"} buildfor i in $@; do upload "$i"done 参考: