背景:由于每次在本地打包完,推送都镜像服务器的时候,都需要登录到镜像服务器,分别执行
1 docker images |grep ***** 2 docker tag 3 docker push
所以为了避免重复的工作,做了一个简单的自动化脚本,自动检测目前最新的镜像,完成打包,升级工作。(加入到环境变量中更方便执行)
#!/bin/sh
url="test.com.cn/"
version=":1"
project=`docker images |head -2 |tail -n 1 | awk '{print $1}'`
full=$url${project##*/}$version
#dockertag=`docker tag $project $full`
echo -e "update project confirm :[$full]"
echo -e "1:confirm/2:cancel"
read key
if [ $key == 1 ];then
echo "confirm this update,please wait......."
echo "docker tag $project running......"
docker tag $project $full
echo "docker tag finshed......"
echo "docker push $full running......."
docker push $full
echo "docker push $full finished"
else
echo "cancel this update."
fi