Copying Docker Images between Hosts

When it comes to copying or moving images, Docker makes it very easy to push your custom images to a public or a private repository on Docker Hub, and this will make them available for future use. However, you might sometimes want to just copy and paste your images to be used on another host that is running on the Cloud or on-premise. A common use case would be a host that simply does not have Internet access to download images from Docker registries.

In this short post, we will go through the steps on how to copy some Docker images between two hosts running in the same local network.

Copying One Image at a Time

Step 1: Save the image as .tar file on the source host

List the exiting images on the host

Save the image you want to copy and provide the destination path. In my case, I will save wordpress needs to be saved in the /tmp folder. No output is displayed if the operation succeeds.

Check that the wordpress.tar file is in the destination path

Step 2: Copy the image to the destination host

Once the image is saved, use rsync or scp to copy the .tar file to the host you want the resulted image to be imported. I’m using scp to copy it over a destination host named dest-srv.

Step 3 Load the image on the destination host

No image is currently present on the destination server.

Run the following command to import the image.

If everything goes fine, you’ll get the following output

Once imported, the Docker images will be visible with the docker images command.

You can now use your image or import other images as per your need.


Copying All Images in Bulk

The previous method saves only one image at at a time. If you are sure you want to use all your existing images, you can save them in bulk using the following the command:

To save all the images in the ~/images/ folder as allimages.tar file, the above command will help. Again, no output is displayed if the command succeeds.

Copy the allimages.tar file to the destination server, then use the same command to import all the images.

Checking that all images have been imported on the destination host.

As you can see, moving images between Docker hosts is amazingly easy just by using two commands. This procedure is possible whether the hosts are on-premise or on the cloud, making images manipulation on isolated servers very flexible.

Find this post interesting. Share it!

Leave a Comment

Your email address will not be published. Required fields are marked *