青成林语

协助他人,成就彼此 ^_^
推送docker镜像小脚本(包含修改daemon.json配置文件)
#!/bin/bash
set -e
set -x
cd /etc/docker
sed -i '2i "insecure-registries":["172.19.12.84"],' /etc/docker/daemon.json
grep "insecure-registries" /etc/docker/daemon.json
if [ $? -eq 0 ]; then
    echo "succeed 配置信任网站 "
else
    echo "failed 请检查配置"
fi
echo "重启docker服务"
systemctl restart docker
#5-12表示5月12日的镜像标签为v1
echo "获取docker运行的容器名"
container=`docker ps|grep -v ID|awk '{print $2}'`
echo "给容器打新的tag"
docker tag $container $container/5-12:v1
echo "在项目中标记镜像"
docker tag $container/5-12:v1 172.19.12.84/zj-school-project/$container/5-12:v1
echo "登陆Harbor仓库"
docker login 172.19.12.84 -u admin -p Harbor12345
if [ $? -eq 0 ]; then
    echo "登陆Harbor仓库成功"
else
    echo "登陆Harbor仓库失败"
fi
echo "开始推送指定镜像到Harbor仓库"
docker push 172.19.12.84/zj-school-project/$container/5-12:v1

 

posted on 2021-05-12 23:00  青成林语  阅读(283)  评论(0编辑  收藏  举报