Skip to content

Instantly share code, notes, and snippets.

@joshua
Created January 21, 2021 14:36
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 joshua/8c787e5df388939e997f4a26e0ec9f15 to your computer and use it in GitHub Desktop.
Save joshua/8c787e5df388939e997f4a26e0ec9f15 to your computer and use it in GitHub Desktop.
Save and Load All Docker Images
#!/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