Wednesday, January 19, 2022
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 pass environment variables to Docker containers?

Intro In application development, it is best practice to separate services from configurations. The Twelve-factor app methodology recommends...

How to rename files and folders in Amazon s3?

Intro: Is it possible to rename files and folders in Amazon S3? How to rename files or folders...

How can we make an S3 bucket public?

Amazon S3 buckets are by default private to avoid accidental exposure of personal data by everyone. But it is possible to...

The difference between public and private subnets in Amazon VPC

Intro Subnets, public and private subnets, these are all networking issues. Therefore, network basics are required to understand...

Recent Comments