Skip to content

Instantly share code, notes, and snippets.

@zsiddiqi
Forked from lalyos/save-all-images.sh
Created December 15, 2017 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsiddiqi/4a09d24ec14f37e3057527b0e829643c to your computer and use it in GitHub Desktop.
Save zsiddiqi/4a09d24ec14f37e3057527b0e829643c to your computer and use it in GitHub Desktop.
script to save all docker image, and load them back
reload() {
source ${BASH_SOURCE[0]}
}
alias r=reload
get-image-field() {
local imageId=$1
local field=$2
: ${imageId:? reuired}
: ${field:? required}
docker images --no-trunc|sed -n "/${imageId}/ s/ \+/ /gp"|cut -d" " -f $field
}
get-image-name() {
get-image-field $1 1
}
get-image-tag() {
get-image-field $1 2
}
save-all-image() {
local ids=$(docker images -q)
local name safename tag
for id in $ids; do
name=$(get-image-name $id)
tag=$(get-image-tag $id)
if [[ $name =~ / ]] ; then
dir=${name%/*}
mkdir -p $dir
fi
echo [DEBUG] save $name:$tag ...
(time docker save -o $name.$tag.dim $name:$tag) 2>&1|grep real
done
}
load-all-image() {
local name safename noextension tag
for image in $(find . -name \*.dim); do
echo [DEBUG] load
tar -Oxf $image repositories
echo
docker load -i $image
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment