練習時的docker部署指令碼

文采杰出發表於2024-03-12

! /bin/sh

接收外部引數

harbor_url=$1
harbor_project=$2
project_name=$3
tag=$4
port=$5

imageName=\(harbor_url/\)harbor_project/\(project_name:\)tag

echo "$imageName"

查詢容器是否存在,存在則刪除

containerId=docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'
if [ "$containerId" != "" ]; then
#停止容器
docker stop $containerId
#刪除容器
docker rm $containerId
echo "成功刪除容器"
fi

查詢映象是否存在,存在則刪除

imageId=docker images | grep -w ${project_name} | awk '{print $3}'
if [ "$imageId" != "" ]; the

相關文章