If you want to export all images at once, create one large tar file:
docker save $(docker images -q) -o /path/to/save/mydockersimages.tar
If you want to save several 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 images, one .tar file per image (not efficient on disk: a common layer is saved in each .tar file):
docker images | awk '{if ($1 ~ /^(openshift|centos)/) print $1 " " $2 " " $3 }' | tr -c "az 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 can also save the list of images so that you can mark the restored images:
docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' > mydockersimages.list
On a remote machine, you can load (import) images:
docker load -i /path/to/save/mydockersimages.tar
and mark 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 on saving / loading read: How to copy Docker images from one host to another without using a repository
Franklin piat
source share