How to save all Docker images and copy to another computer

I have a list of the images below on my system and I want to copy all these images to a remote computer.

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE u14_py269 latest 6a1ec0b508b3 4 days ago 885.9 MB u12_py273 latest c2a804894851 4 days ago 686 MB u12_core latest 0d61eba80df2 4 days ago 629.1 MB c6_py266 latest cb1a94742d59 4 days ago 1.32 GB c6_core latest 77c2ed19d87f 4 days ago 1.278 GB c7_py275 latest bb1d3de68452 4 days ago 1.117 GB c7_core latest ca14a76e9cca 4 days ago 1.081 GB u14_py35 latest d110c7e4a1f5 5 days ago 914.5 MB u14_py34 latest 085a37cb8614 5 days ago 830.7 MB u14_py276 latest 8927c6167930 5 days ago 834.1 MB u14_core latest 93ead5abc25b 5 days ago 776.9 MB centos centos6 36877b5acebb 5 days ago 228.9 MB ubuntu latest 36248ae4a9ac 5 days ago 188 MB ubuntu 12.04 94a7cb19a65b 5 days ago 137.8 MB edgester/gerrit latest ce4e3238052a 6 days ago 735.2 MB u14_as374_py276 latest fa5fb7189d70 11 days ago 1.497 GB c721_as373_py275 latest 03ccf6961d0c 11 days ago 844.3 MB c721_as373_py35 latest b5fece3dd45b 11 days ago 1.127 GB c171_con_core latest 8af0d24a38a0 2 weeks ago 377.2 MB u14_as374_php55 latest 29df638e363a 3 weeks ago 1.073 GB j_u14_as374_php55 latest 29df638e363a 3 weeks ago 1.073 GB centos centos7 c8a648134623 8 weeks ago 196.6 MB centos latest c8a648134623 8 weeks ago 196.6 MB j_u14_as374_py276 latest 28f379d60882 10 weeks ago 871.5 MB ubuntu 14.04 89d5d8e8bafb 10 weeks ago 187.9 MB 

I am currently using the method suggested for saving and loading Docker images , but I believe that there should be a better way to handle all the images.

+24
docker
source share
7 answers

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

+55
source share

Save all images with name:tag in a single tar file:

 docker save $(docker images | sed '1d' | awk '{print $1 ":" $2 }') -o allinone.tar 

Then download all the images:

 docker load -i allinone.tar 
+10
source share

With Windows Server hosting, the command is a little different. Using the answer #EthanSN, I found that the following worked - using go formatting:

  docker save $(docker images --format '{{.Repository}}:{{.Tag}}') -o allinone.tar 

And the boot command:

  docker load -i allinone.tar 

It worked perfectly, without having to import a machine to load any images.

+7
source share

Many thanks to all your awnsers, but I found a simple and safe solution for saving :

 docker save -o ubuntu.tar myjenk:latest jenkins/jenkins:lts REPOSITORY TAG myjenk latest jenkins/jenkins lts 

after image recovery :

 docker load < ubuntu.tar 
+3
source share

You can use Bash to iterate over the response to docker images docker save -o <save image to path> <image name> on each image, and then (assuming you saved them all in one folder) you can compress it and scp this is to the remote host.

+2
source share

Using the registry, you can have a workflow similar to Git. Change the local container, copy the changes to the local image, and then click the image in the registry. Then you can pull out the image from the remote computer.

You can use the public Docker Hub, or you can configure your own registry server.

https://docs.docker.com/registry/

+1
source share

Script for executing the function of saving and loading Docker (tested and tested):

Docker Save:

 #!/bin/bash #files will be saved in the dir 'Docker_images' mkdir Docker_images cd Docker_images directory='pwd' c=0 #save the image names in 'list.txt' doc= docker images | awk '{print $1}' > list.txt printf "START \n" input="$directory/list.txt" #Check and create the image tar for the docker images while IFS= read -r line do one='echo $line | awk '{print $1}'' two='echo $line | awk '{print $1}' | cut -c 1-3' if [ "$one" != "<none>" ]; then c=$((c+1)) printf "\n $one \n $two \n" docker save -o $two$c'.tar' $one printf "Docker image number $c successfully converted: $two$c \n \n" fi done < "$input" 

Docker Download:

 #!/bin/bash cd Docker_images/ directory='pwd' ls | grep tar > files.txt c=0 printf "START \n" input="$directory/files.txt" while IFS= read -r line do c=$((c+1)) printf "$c) $line \n" docker load -i $line printf "$c) Successfully created the Docker image $line \n \n" done < "$input" 
+1
source share

All Articles