You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
891 B
42 lines
891 B
harbor_addr=$1
|
|
harbor_repo=$2
|
|
project_name=$3
|
|
version=$4
|
|
host_port=$5
|
|
container_port=$6
|
|
|
|
imageName=$harbor_addr/$harbor_repo/$project_name:$version
|
|
|
|
echo $imageName
|
|
|
|
containerId=`docker ps -a |grep $project_name | awk '{print $1}'`
|
|
|
|
echo $containerId
|
|
# 停止容器
|
|
if [ -n "$containerId" ]; then
|
|
echo "stop and remove container"
|
|
docker stop $containerId
|
|
docker rm $containerId
|
|
fi
|
|
|
|
imageId=`docker images |grep $project_name | awk '{print $2}'`
|
|
echo $imageId
|
|
# 删除镜像
|
|
if [[ "$imageId" =~ "$version" ]]; then
|
|
echo "remove image"
|
|
docker rmi -f $imageName
|
|
fi
|
|
|
|
|
|
# 拉取镜像
|
|
docker login -u admin -p Harbor12345 $harbor_addr
|
|
docker pull $imageName
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "pull image success"
|
|
# 启动容器
|
|
docker run -d -p $host_port:$container_port --name $project_name $imageName
|
|
echo "start container success"
|
|
else
|
|
echo "pull image fail"
|
|
fi |