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.
 
 
 
 
 
 

29 lines
882 B

#! /bin/sh
#镜像名称
image_name=$1
#标签
image_tag=$2
#镜像仓库地址
registry_url=$3
#备份tag
image_bak_tag=$4
#带仓库地址镜像名称
image_full_name=$registry_url/$image_name
colunm3='$3'
# 获取当前正在运行的镜像
echo "docker images | grep -w $image_full_name | awk '{print $colunm3}'"
image_check_command=`docker images | grep -w $image_full_name | awk '{print $3}'`
echo "image_check_command-----$image_check_command"
if [ "$image_check_command" != "" ] ; then
# 将运行的镜像,重新修改tag命名为备份tag
echo "docker tag ${image_full_name}:${image_tag} ${image_full_name}:${image_bak_tag}"
docker tag ${image_full_name}:${image_tag} ${image_full_name}:${image_bak_tag}
#将本地刚重命名的镜像删除
echo "docker rmi ${registry_url}/${image_name}:$image_bak"
docker rmi ${registry_url}/${image_name}:$image_bak
fi