我有20张已映射的图像,现在我想将这些图像加载到另一个系统上。但是,加载本身需要30到40分钟。我相信所有图像都是彼此独立的,因此所有图像加载应并行进行。
我尝试了诸如在background(&)和wait
中运行load命令的解决方案,直到加载完成,但是观察到这花费了更多时间。非常感谢您的任何帮助。
注意:-不确定-i
至docker load
命令的选项。
答案 0 :(得分:0)
为了加快提取/保存过程,您可以使用以下摘录中的想法:
#!/usr/bin/env bash
TEMP_FILE="docker-compose.image.pull.yaml"
image_name()
{
local name="$1"
echo "$name" | awk -F '[:/]' '{ print $1 }'
}
pull_images_file_gen()
{
local from_file="$1"
cat <<EOF >"$TEMP_FILE"
version: '3.4'
services:
EOF
while read -r line; do
cat <<EOF >>"$TEMP_FILE"
$(image_name "$line"):
image: $line
EOF
done < "$from_file"
}
save_images()
{
local from_file="$1"
while read -r line; do
docker save -o /tmp/"$(image_name "$line")".tar "$line" &>/dev/null & disown;
done < "$from_file"
}
pull_images_file_gen "images"
docker-compose -f $TEMP_FILE pull
save_images "images"
rm -f $TEMP_FILE
images-包含所需的Docker映像名称,逐行列出。
祝你好运!
答案 1 :(得分:0)
尝试
find /path/to/image/archives/ -iname "*.tar" -o -iname "*.tar.xz" |xargs -r -P4 -i docker load -i {}
这将并行加载Docker映像存档(将-P4
调整为所需的并行加载数,或者将-P0
设置为http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg
以实现无限并发)。