docker 镜像迁移脚本

#!/bin/bash

TAG_PREFIX=

save(){
    if [ ! -d "./images" ]; then
        mkdir images
    fi
    cd images
    docker images --format "{{.ID}} {{.Repository}}:{{.Tag}} {{.Size}}" |grep $TAG_PREFIX > images_pull.txt
    while read line
    do
        image_id=`echo $line | awk '{print $1}'`
        image_repository=`echo $line | awk '{print $2}'`
        image_size=`echo $line | awk '{print $3}'`
        docker save -o $image_id.tar $image_repository && \
        echo "Image $image_repository saved, size $image_size"
    done < images_pull.txt
}

load(){
    cd images
    while read line
    do
        image_id=`echo $line | awk '{print $1}'`
        image_repository=`echo $line | awk '{print $2}'`
        docker load -i $image_id.tar && \
        echo "Image $image_repository loaded"
    done < images_pull.txt
}
if [ -z "$1" ]; then
    echo "Usage: image_operation.sh [save|load]"
fi

eval $1

你可能感兴趣的:(docker,容器,运维)