background
When deploying in some environments that do not have access to the external network, offline deployment projects are required, so it is necessary to export the image and then export it locally. Make a script to batch process the java projects that need to be exported.
Export local image
The shell script is as follows:
#/bin/bash
allimages=$(docker images --format “{
{.Repository}}:{
{.Tag}}”)
for x in $allimages
do
tar_name=$x".tar"
#echo $tar_name
#去掉尾部"
tmp=${x%?}
#去掉头部#
tmp=${tmp#?}
#获取导出的名字,处理左侧字符
tar=${tmp#*/}
#获取导出的名字,处理左侧的数据
tar=${tar#*/}
#获取导出的名字,处理:
tar=${tar%:*}
echo $tar
#echo $tmp
docker save -o tars/“$tar”.tar $tmp
done
Import local mirror
The shell script is as follows:
#!/bin/bash
#镜像文件基础目录
base=/data/imas/server_soft/tars
cd $base
for f in $base/*
do
if [[ $f == *.tar ]]
then
# echo $f
#导入本地镜像
docker load -i $f
fi
done
[Remarks] The imported image tag still retains the original