Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy docker images from one host to another?

Tags:

docker

Let say I have 10 docker images. In all the 10 docker images many layers are similar.

While using docker save -o, saved image is standalone and therefore images size grow bigger. (~ For 10 images size is around 9GB )

After pulled docker images, I explore:

/var/lib/docker
  --- aufs (~3GB only)
  --- containers (Few KBs)
  --- image (Few KBs)
  --- ...
  --- mnt

Is there anyway to efficiently export images ?

I also tried copy-paste aufs and image folder to new host. But some containers can't start.

While inspect log:

/usr/bin/sudo must be owned by uid 0 and have the setuid bit set

Note: I already referred this . This question is not duplicate of it. It didn't solve my use case which I mentioned above.

like image 817
rajagopalx Avatar asked Dec 15 '16 00:12

rajagopalx


People also ask

Can I move a docker image to another host?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.

How do I push docker images from one registry to another?

To push any local image to Container Registry using Docker or another third-party tool, you need to first tag it with the registry name and then push the image.

Can you export a docker image?

Yes! Let the docker save image command and the docker export image command do the trick! In this tutorial, you'll learn how to save and export containers and images for sharing by running Docker commands.


1 Answers

I don't know whether this is a correct approach. But Below method worked for me. I tested with 30 Kolla Openstack Docker Images.

Why I have problem with docker save ?

As I said, I have 30 docker images. While I save using docker save -o <save image to path> <image name>. Total size is 15 GB which is too BIG to portable.

What I did ?

Long Story Short: I copied aufs and image folder carefully.

Step 1:

In the machine you want to export : Make sure you have only images(which are to be export). Remove all the containers which are running and stopped.

In the machine you want to import: Make sure You don't have any images and containers.

Step 2: tar -cvf docker-images.tar /var/lib/docker/aufs /var/lib/docker/image It will zip all of your image layers and its database into a single tar file. Size is only 3 GB

Step 3: In the machine, you want to import images,

tar -xvf docker-images.tar -C /var/lib/docker/.

Now restart docker. service docker restart.

like image 158
rajagopalx Avatar answered Sep 30 '22 14:09

rajagopalx