Last active
September 17, 2018 07:10
-
-
Save yannhowe/119452d3f54b58494fd421234304ddef to your computer and use it in GitHub Desktop.
Get list of docker images, save, then load
This file contains hidden or 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
nginx:1.15 | |
registry:2 | |
python:3.7-stretch | |
node:8.12-jessie |
This file contains hidden or 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 | |
# pull images from internet | |
while read image; do docker pull "$image"; done <docker-images.list | |
docker images | |
# save to one big tar file | |
DATE=`date +%Y-%m-%d-%H%M%S` | |
docker save $(docker images -q) -o ./dockerimages-$DATE.tar | |
docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' > dockerimages-$DATE.list | |
# remove images | |
#docker rmi -f $(docker images -a -q) | |
#docker images | |
# move tar and list to staging folder | |
mv ./dockerimages-* /staging-folder/ |
This file contains hidden or 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 | |
# load from tar file to host images | |
docker load -i dockerimages-*.tar | |
docker images | |
# tag all images | |
while read REPOSITORY TAG IMAGE_ID | |
do | |
echo "== Tagging $REPOSITORY $TAG $IMAGE_ID ==" | |
docker tag "$IMAGE_ID" "$REPOSITORY:$TAG" | |
done < dockerimages*.list | |
docker images | |
rm dockerimages-*.tar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment