Created
March 31, 2018 12:42
-
-
Save attila123/8f60a0ebce15b6065975ba35e3be7d75 to your computer and use it in GitHub Desktop.
save all docker images with repo + tag information
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 -eu | |
# Save all docker images with repo+tag in the current directory as .tar files. | |
# It was not tested with images with multiple tags. | |
# Images can be loaded from bash shell e.g.: | |
# for img in *.tar ; do docker load -i $img ; done | |
# Written by Attila Vangel at 2018-03-31 | |
# skip header line | |
docker images | tail --lines=+2 | while read LINE ; do | |
REPO=`echo ${LINE} | awk '{print $1}'` | |
TAG=`echo ${LINE} | awk '{print $2}'` | |
ID=`echo ${LINE} | awk '{print $3}'` | |
# Replace '/' characters in REPO with '_' | |
FILENAME=${REPO//\//_}__${TAG}__${ID}.tar | |
echo "Saving docker image ${REPO}:${TAG} as ${FILENAME} ..." | |
docker save ${REPO}:${TAG} > ${FILENAME} | |
done |
thanks for sharing this code. a suggestion to simplify: it looks to me like you could read directly into the variables (read REPO TAG ID junk
) instead of read followed by 3 calls to awk.
find . -name "*.tar" -exec docker load -i '{}' ;
find . -name "*.tar" -exec docker load -i '{}' \ ;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Load images:
find . -name "*.tar" -exec docker load -i '{}' ;