如何将Docker映像从一台主机复制到另一台主机? [英] How to copy docker images from one host to another?

查看:514
本文介绍了如何将Docker映像从一台主机复制到另一台主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有10个docker映像。在所有10个docker映像中,许多层都是相似的。

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

使用 docker save -o 时,保存的图像是独立的,因此图像的尺寸会变大。 (〜10张图片的大小约为9GB)

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

提取docker图片后,我将探索:

After pulled docker images, I explore:

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

为了有效地导出图像?

我还尝试了将aufs和image文件夹复制粘贴到新主机。但是某些容器无法启动。

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

同时检查日志:

/ usr / bin / sudo必须由uid 0并设置了setuid位

注意:我已经引用了。这个问题不是重复的。

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

推荐答案

我不知道这是否是正确的方法。但是下面的方法对我有用。我用30个 Kolla Openstack Docker映像进行了测试。

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

为什么我在 docker save 上遇到问题?

Why I have problem with docker save ?

正如我所说,我有30个docker镜像当我使用 docker保存时,保存-o<将图像保存到路径> <图片名称> 。总大小为15 GB,太大了,无法携带。

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.

我做了什么?

长话短说::我仔细复制了aufs和图片文件夹。

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

步骤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.

步骤2: tar -cvf docker-images.tar / var / lib / docker / aufs / var / lib / docker / image 它将所有图像层及其数据库压缩到一个tar文件中。 大小仅为3 GB

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

第3步:在计算机中,要导入图像,

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

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

现在重新启动docker。 服务docker restart

Now restart docker. service docker restart.

这篇关于如何将Docker映像从一台主机复制到另一台主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆