Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodolfovalentim/2d0b364f916264be6de2cb12d44c2b31 to your computer and use it in GitHub Desktop.
Save rodolfovalentim/2d0b364f916264be6de2cb12d44c2b31 to your computer and use it in GitHub Desktop.
33
down vote
If you want to export all images at once, create one big tar file:
docker save $(docker images -q) -o /path/to/save/mydockersimages.tar
If you want to save multiples images in one .tar file:
IDS=$(docker images | awk '{if ($1 ~ /^(debian|centos)/) print $3}')
docker save $IDS -o /path/to/save/somedockersimages.tar
Finally, if you want to export multiple many images, with one .tar file per images (not disk efficient: common layer are saved in each .tar file):
docker images | awk '{if ($1 ~ /^(openshift|centos)/) print $1 " " $2 " " $3 }' | tr -c "a-z A-Z0-9_.\n-" "%" | while read REPOSITORY TAG IMAGE_ID
do
echo "== Saving $REPOSITORY $TAG $IMAGE_ID =="
docker save -o /path/to/save/$REPOSITORY-$TAG-$IMAGE_ID.tar $IMAGE_ID
done
You may also want to save the list of images so that the restored images can be tagged:
docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' > mydockersimages.list
On the remote machine, you can load (import) the images:
docker load -i /path/to/save/mydockersimages.tar
and tag the imported images:
while read REPOSITORY TAG IMAGE_ID
do
echo "== Tagging $REPOSITORY $TAG $IMAGE_ID =="
docker tag "$IMAGE_ID" "$REPOSITORY:$TAG"
done < mydockersimages.list
For more information about save/load, read: How to copy docker images from one host to another without via repository?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment