docker镜像转存脚本

#需要有外网服务器!!!

#!/bin/bash
echo -e "\E[0;41m 私有仓库需要提前登录!! \E[0m \n"

checkEv() {
if [ $1 == 0 ];
then
  echo -e "\E[0;42m 成功 !!!! \E[0m \n"
else
  echo -e "\E[0;41m 失败 !!! \E[0m \n"
fi
}


imagePath=$1
#替换为自己的镜像仓库地址
aliImagePath="registry.cn-chengdu.aliyuncs.com/gcriosa"
imageVersion=`echo ${imagePath} | awk -F\/ '{print $NF}'`

echo -e "\E[0;42m 拉取镜像 !!!! \E[0m \n"
docker pull ${imagePath}
checkEv $?

echo -e "\E[0;42m 镜像路径转换 !!!! \E[0m \n"
docker tag ${imagePath} ${aliImagePath}/${imageVersion}
checkEv $?

echo -e "\E[0;42m 上传到私有仓库 !!!! \E[0m \n"
docker push ${aliImagePath}/${imageVersion}
checkEv $?


echo -e "\E[0;41m 清理镜像!!! \E[0m"
docker rmi ${imagePath}
checkEv $?
docker rmi ${aliImagePath}/${imageVersion}
checkEv $?
posted @ 2023-03-18 21:43  炒鸡蛋  阅读(34)  评论(0编辑  收藏  举报