Created
January 21, 2021 14:36
-
-
Save joshua/8c787e5df388939e997f4a26e0ec9f15 to your computer and use it in GitHub Desktop.
Save and Load All Docker Images
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 | |
case "${1}" in | |
"save") | |
# dump image tags so they can be restored later | |
echo "saving tags to image-tags.txt" | |
docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' > allimages-tags.txt | |
# save all images to a single tar | |
echo "saving images to allimages.tar" | |
docker save $(docker images -q) -o allimages.tar | |
;; | |
"load") | |
echo will load | |
exit 1 | |
# load all images | |
# this may take a while depending on the size and number of images | |
echo "loading allimages.tar" | |
docker load -i allimages.tar | |
# restore original image tags | |
echo "restoring tags" | |
while read REPOSITORY TAG IMAGE_ID | |
do | |
echo "== Tagging $REPOSITORY $TAG $IMAGE_ID ==" | |
docker tag "$IMAGE_ID" "$REPOSITORY:$TAG" | |
done < allimages-tags.txt | |
;; | |
*) | |
echo "usage: ${0} [save|load]" | |
exit 1 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment