shell批量导出镜像的一个例子

目标:导出文本中的镜像,并以后缀+tar命名保存镜像,比如emqttd:v1.4.1.tar

1.txt

    image: registry.cn-hangzhou.aliyuncs.com/elements/captcha:v1.3.7
    image: registry.cn-hangzhou.aliyuncs.com/elements/statistic:v1.3.7
    image: registry.cn-hangzhou.aliyuncs.com/elements/report:v1.3.7
    image: registry.cn-hangzhou.aliyuncs.com/elements/kv:v1.3.7

执行下面命令得到镜像名文件

for x in `cat 1.txt`; do echo $x | awk -F "image:" '{print $1}' >> 2.txt; done

 

2.txt

registry.cn-hangzhou.aliyuncs.com/elements/emqttd:v1.4.1
registry.cn-hangzhou.aliyuncs.com/elements/sense:v1.3.7
registry.cn-hangzhou.aliyuncs.com/elements/touch:v1.3.7
registry.cn-hangzhou.aliyuncs.com/elements/ivpn:v1.3.7
registry.cn-hangzhou.aliyuncs.com/elements/openvpn
registry.cn-hangzhou.aliyuncs.com/elements/elements-ui:v1.3.8
registry.cn-hangzhou.aliyuncs.com/elements/config-server:v3.1.0
registry.cn-hangzhou.aliyuncs.com/gehc/ib-api:r1.1.0
registry.cn-hangzhou.aliyuncs.com/gehc/ib-service:r2.0.0

 

1.sh

#/bin/bash

for x in `cat 2.txt`
do
    version_name=`echo ${x} | awk -F '/' '{print $3}'`
    tar_name=$version_name".tar"
    echo $x
    echo $tar_name
    docker save `echo $x` > `echo ${tar_name}`
done

 

posted @ 2021-03-31 11:46  坚强的小蚂蚁  阅读(244)  评论(0编辑  收藏  举报