创建一个脚本,脚本内容如下,执行脚本导入镜像并上传
#!/bin/bash
## Enter docker image file path
file_path=/root
## Enter your host ip
host_ip=192.168.200.202
## Filter docker image files
image_files=$(ls $file_path -I "*registry*" |grep .tar)
for file in $image_files
{
## Get the json file in docker image file
image_jsons=$(tar -tf $file_path/$file |awk -F "/" '{print $1}' |grep .json)
for json in $image_jsons
{
## Filter json file
if [[ $json != manifest.json ]] ; then
## Get docker image id
json_name=${json%.*}
image_id=${json_name:0:12}
fi
}
## Get docker image file name
file_name=${file%.*}
sum=0
for (( i=1; i<=${#file_name}; i++ ))
{
## Convert filename to array
image_name[$i]=$(echo "$file_name" |cut -c $i)
## Find the location of "_"
if [[ ${image_name[$i]} = _ ]] ; then
num[$sum]=$i
((sum++))
fi
}
## Modify special characters
for (( i=0; i<=$sum - 1; i++ ))
{
image_name[${num[$i]}]=/
if [[ $i = ${#num} ]] ; then
image_name[${num[$i]}]=:
fi
}
tag_name=''
for (( i=1; i<=${#file_name}; i++ ))
{
tag_name=$tag_name${image_name[$i]}
}
## Load docker image
docker load < $file_path/$file
## Tag and Push docker image
docker tag $image_id $host_ip:5000/$tag_name
docker push $host_ip:5000/$tag_name
}