How to copy Docker images to hosts without using a repository

Problem statement

Suppose there are two machines, XX and YY. There is a Docker image in XX that has to be sent to YY. Here, we shouldn’t use a Docker repository to store the image from XX and pull the image to YY from the repository.

Solution

The solution to this problem lies in using the following commands:

  • docker save
  • ssh
  • docker load

These are the steps we follow to move a Docker image between hosts:

Step 1:

We use the docker save command to create a tar file of the docker image in machine XX.

docker save -o image.tar docker_image_name

Then, we create the image.tar file in machine XX.

Step 2:

We use the ssh command to send the tar file from machine XX to machine YY.

The syntax for the scp command is as follows:

scp  [source content location] [destination content location]
scp /users/X/Desktop/image.tar Y@www.server2.com:/users/Y/Downloads

Now, the tar file is in machine YY.

Step 3:

We use the docker load command to load the tar file.

cat ./image.tar  | docker load

Free Resources