目录
目标服务器拉取镜像,并运行
准备脚本
修改任务配置
vi deploy.sh
chmod a+x deploy.sh
#!/bin/bash harbor_address=$1 harbor_repo=$2 project=$3 version=$4 host_port=$5 container_port=$6 imageName=$harbor_address/$harbor_repo/$project:$version echo $imageName #查看正在运行容器的ID containerId=`docker ps -a | grep ${project} | awk '{print $1}'` echo $containerId #停止正在运行的容器,并删除容器 if [ "$containerId" != "" ]; then docker stop $containerId docker rm $containerId fi tag=`docker images | grep ${project} | awk '{print $2}'` echo $tag #镜像对应的版本是否存在,并删除镜像 if [[ "$tag" =~ $version ]]; then docker rmi $imageName fi docker login -u admin -p Harbor12345 ${harbor_address} docker pull $imageName docker run -d -p $host_port:$container_port --name $project $imageName echo "SUCCESS"
./deploy.sh 192.168.171.111:80 repository jenkins-demo V3.0.0 8081 8080
echo $PATH
mv /home/deploy.sh /usr/bin/
scp deploy.sh 192.168.171.113:/usr/bin/