Wednesday, October 4, 2023
Home CONTAINERIZATION How to copy Docker images from one host to another without using...

How to copy Docker images from one host to another without using a repository?

Description

You need to copy Docker images from one host to another for various reasons. In this case, using a public or private registry is typically the first option. For instance, you can push your image to a repository in Docker Hub. But you must have a Docker Hub account. Then you need to tag the image and push it to the repo. Now, you should go to the machine you want to move. With the docker pull command, download your image from the Docker Hub repo to that host machine. As you see, it is a long haul. But what if we don’t want to use a repository? I will show you how to cut corners.

Copy Docker images from one host to another by tar files

The most common and robust method is saving and loading images from tar files. Docker allows you to save images into tar files using the docker save. This command also compresses images and enables sharing them easily and quickly. You can then use the docker load command to load the Docker image back from the tar file into another host. It is that much easy to copy Docker images from one host to another without using a repository.

First of all, let’s check the existed images by running docker images:

List of the host machine images

To export the alpine image to a tar file, run the docker save -o <tar file path in source host machine> <image_name> command, specifying a name for the .tar file, and the docker image. This will save the docker image locally.

Saving the image

Next, copy your image to your target system. You could use scp or another file transfer tool such as rsync. Then we will connect to the remote machine which is another host via ssh.

Copying the images to remote host

When I check the destination path of the tar file which we sent, alpiner.tar has already been there. So transferring the tar file of the image is successfully completed. Now let’s list the images on this host to see whether alpine images exist or not there.

List the images of remote host

As you see above, there is no image on the target host because we have not imported the image yet. The docker load -i <image.tar> command will load the docker image from the tar file.

Final scene: List and see the transferred image on the remote host

As a last option, you can also use another tool called Skopeo, which we published an introduction post about that earlier. Checkout from this link.

Skopeo can help you to sync or move images.

Conclusion

To sum up, we learn how to copy Docker images from one host to another without using any Docker registry or repository. In between, either with the help of docker save/docker load command pair or with another tool called Skopeo are offered.

Let us know if you are using other methods or tools to accomplish this task.

Thanks.

Mustafa Gonen
DevOps engineer, helps companies to balance their needs throughout the software development life cycle, from coding and deployment to maintenance and updates by automation. He believes the beauty of diversity. Working in DevOps culture and being a part of this harmony makes him highly motivated and satisfied.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular

How to query EC2 tags from within the instance?

Intro To help you manage your instances, images, and other Amazon EC2 resources, you can assign your own...

How to install Python3 on Amazon Linux 2?

Intro Python is an object-oriented programming language that is widely used. In addition to that, it's free and...

How to connect an AWS EC2 instance with FileZilla and do SFTP?

Intro EC2 is one of the essential services of Amazon Web Services (AWS), providing highly available and scalable...

How to install AWS CLI v2 on Linux?

Intro Whether you’ve been using AWS for some time or you are a novice, you may have noticed...

Recent Comments