Skip to content

Instantly share code, notes, and snippets.

@yannhowe
Last active September 17, 2018 07:10
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 yannhowe/119452d3f54b58494fd421234304ddef to your computer and use it in GitHub Desktop.
Save yannhowe/119452d3f54b58494fd421234304ddef to your computer and use it in GitHub Desktop.
Get list of docker images, save, then load
nginx:1.15
registry:2
python:3.7-stretch
node:8.12-jessie
#!/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/
#!/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