Created
August 7, 2018 22:06
Star
You must be signed in to star a gist
minimal docker image backup/restore. used once when resetting the docker/mac VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eou pipefail | |
dump_images() { | |
for i in $(docker images -q | uniq); do | |
local tarball="$i.tar.gz" | |
if [[ -e "$tarball" ]]; then | |
echo "$tarball exists, skipping $i" | |
continue | |
fi | |
echo "dumping $i to $tarball ..." | |
if ! docker save "$i" | pigz >"$i.tar.gz"; then | |
echo "ERROR saving image '$i'" | |
rm -f -- "$tarball" | |
fi | |
done | |
} | |
dump_tags() { | |
echo "dump tags to ./tags.txt" | |
docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' >tags.txt | |
} | |
main() { | |
dump_images | |
dump_tags | |
} | |
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eou pipefail | |
load_images() { | |
for i in *.tar.gz; do | |
echo "==> loading image $i" | |
if docker images -q | grep -q "${i%%.*}"; then | |
echo " ==> image $i already loaded, skipping" | |
continue | |
fi | |
gunzip -c "$i" | docker load | |
done | |
} | |
load_tags() { | |
while read -r REPO TAG IMAGE; do | |
echo "==> Tagging $IMAGE: $REPO:$TAG" | |
if ! docker tag "$IMAGE" "$REPO:$TAG"; then | |
echo " WARNING failed to tag $IMAGE '$REPO:$TAG'" | |
continue | |
fi | |
done < ./tags.txt | |
} | |
main() { | |
load_images | |
load_tags | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment