How to copy Docker image from one machine to another?

How to copy Docker image from one machine to another?

Contents

  1. Docker image
  2. Step 1 : Get the docker repository and tag name in machine 1
  3. Step 2 : Save the Docker image as a tar file in machine 1
  4. Step 3 : Copy the tar file to machine 2
  5. Step 4 : Load the image into Docker (in the machine 2)

Docker image

A Docker image is an executable package that includes everything needed to run a container: the code, a runtime, libraries, environment variables, and configuration files. The docker images can be stored in public or private repository.?Docker Hub?is a public repository where we can share the image to Docker community. But the companies have private repository to store their docker images.

Lets consider that we have two servers to run our docker images. One server have access to pull the docker image from the private repository. On the other hand, another server doesn’t have access to pull the docker image. But using docker commands, we can copy the docker image from one machine to another. In this article, we are explaining the steps to copy the docker image from one server to another server.

Step 1 : Get the docker repository and tag name in machine 1

The command?docker images?will show all the images details, their repository, tags, and size. As we can see below, it is showing the repository and tag name for each docker image. In this example, we are going to copy the docker image with the tag name as app_build_001.

No alt text provided for this image

Step 2 : Save the Docker image as a tar file in machine 1

The command?docker save?is used to save the docker image as tar file. As mentioned below, we need to mention the repository name and tag name of the docker image. Also we need to give the output tar file name.

	
docker save -o <generated tar file name> <repository_name:tag_name>1        

Example?:

docker save -o app_build_001.tar artifactory.rc.com/repo/test_app_snapshots:app_build_001        

The tar file?app_build_001.tar?is created successfully in the directory where we executed this command.

Step 3 : Copy the tar file to machine 2

Now we can use?cp, scp or rsync?command to copy the tar file to another machine. In this example, we are showing the scp command for reference.

scp app_build_001.tar remote_username@172.10.10.2:/remote/directory        

Step 4 : Load the image into Docker (in the machine 2)

Once we copy the tar file to respective machine, we need to run?docker load?command to load the docker image from tar file. Lets execute this command for the tar file app_build_001.tar

docker load -i <path to image tar file>        

Example


docker load -i app_build_001.tar	
        

The docker image app_build_001 is successfully loaded in the respective machine. Now it is ready to deploy our application in docker container.


Ravi Lekhwani

Nvidia, Ex-Meta, Ex-Capgemini, 4G, 5G, RAN Engineer

6 个月

Abhishek Rana, thanks for the article. Just one typo, additional "1" at the end in the docker save command.

Akshay Jain

Senior AI Engineer @Netweb | Gen AI | M.Tech. @ IIITA (MLIS) | GATE'21 CSE - 1748 AIR

1 å¹´

great work

Habib Moradi

Founder of E-Mage . | AI-Powered Agent Building Platform. | Insight Mining Platform. | Extracting Insight from Raw Data. | AI-Powered Full-Body MRI for Business.

1 å¹´

Awesome. Thanks.

Aviv Vinograzki ???♂?

Senior Penetration Tester | Cyber Security Consultant | AI | eMAPT | CRTE | CVEs

1 å¹´

Thanks allot. Good tutorial!

hesam mohamadian

Linux Administrator, VOIP Engineer

1 å¹´

Thanks for your useful guide its practical and simple

要查看或添加评论,请登录

Abhishek Rana的更多文章

社区洞察

其他会员也浏览了