docker build -t mytest:$tag .
docker login -u admin -p Harbor12345 178.119.30.133:80
docker tag mytest:$tag 178.119.30.133:80/repo/mytest:$tag
docker push 178.119.30.133:80/repo/mytest:$tag
部署项目需要通过Publish Over SSH插件,让目标服务器执行命令。为了方便一次性实现拉取镜像和启动的命令,推荐采用脚本文件的方式。
添加脚本文件到目标服务器,再通过Publish Over SSH插件让目标服务器执行脚本即可。
deploy.sh
harbor_addr=$1
harbor_repo=$2
project=$3
version=$4
port=$5
imageName=$harbor_addr/$harbor_repo/$project:$version
echo $imageName
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 -f $imageName
fi
docker login -u admin -p Harbor12345 $harbor_addr
docker pull $imageName
docker run -d -p $port:$port --name $project $imageName
echo "Success"
[root@178-119-30-133 ~]# ./deploy.sh 178.119.30.133:80 repo mytest v3.0.0 8081