You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
988 B
44 lines
988 B
#!/bin/bash
|
|
# 描述:利用国内镜像源加速拉取,但保留原始镜像名称
|
|
# 作者:你的名字
|
|
# 日期:$(date +%Y-%m-%d)
|
|
|
|
# 定义镜像列表文件
|
|
IMAGE_LIST="images.txt"
|
|
LOG_FILE="pull.log"
|
|
FAILED_FILE="failed.txt"
|
|
|
|
# 清空旧日志
|
|
> "$LOG_FILE"
|
|
> "$FAILED_FILE"
|
|
|
|
# 开始拉取
|
|
total=$(wc -l < "$IMAGE_LIST")
|
|
current=1
|
|
|
|
echo "===== 开始批量拉取镜像(共 $total 个) ====="
|
|
while read -r image; do
|
|
echo "[$current/$total] 拉取镜像: $image"
|
|
|
|
# 执行拉取命令
|
|
if docker pull $image >> "$LOG_FILE" 2>&1; then
|
|
echo "成功: $image"
|
|
else
|
|
echo "失败: $image" | tee -a "$FAILED_FILE"
|
|
fi
|
|
|
|
((current++))
|
|
echo "----------------------------------------"
|
|
done < "$IMAGE_LIST"
|
|
|
|
# 输出统计结果
|
|
success=$(grep -c "成功:" "$LOG_FILE")
|
|
failed=$(wc -l < "$FAILED_FILE")
|
|
|
|
echo "===== 拉取完成 ====="
|
|
echo "成功: $success 个"
|
|
echo "失败: $failed 个"
|
|
[[ $failed -ne 0 ]] && echo "查看失败列表: cat $FAILED_FILE"
|
|
|
|
|