简体   繁体   English

Docker:将Docker层合并为映像

[英]Docker: combine docker layers into image

The origin of this question is that the pulling from docker private registry is super slow. 这个问题的根源是从docker私有注册表中拉出的速度非常慢。

Then I figure out that the speed of wget through registry remote API is all right. 然后我发现通过注册表远程API进行wget的速度是可以的。

Now I get layers of one image. 现在,我得到一张图像的图层。 How can I load it as image to my docker daemon? 如何将其作为映像加载到我的docker守护进程中?

ps: PS:

I tried docker load < layer.0 , where layer.0 is the base image of all layers. 我尝试了docker load < layer.0 ,其中layer.0是所有图层的基本映像。

And the result as following. 结果如下。

FATA[0015] Error: open /home/docker/data/docker/tmp/docker-import-087506163/repo/etc/json: no such file or directory FATA [0015]错误:打开/ home / docker / data / docker / tmp / docker-import-087506163 / repo / etc / json:无此类文件或目录

All layers are diffs you have to load them all for your "image" to be complete. 所有图层都是差异,您必须全部加载它们才能使“图像”完整。 There is no single image file which contains all your layers. 没有一个包含所有图层的图像文件。 This is by design, because it allows sharing of those layers as a base for subsequent images. 这是设计使然,因为它允许共享这些图层作为后续图像的基础。

You can flatten an image with docker export and then docker import. 您可以先使用docker export平坦化映像,然后再使用docker import进行平坦化。 That will take all the existing layers and export them as a single file system image, in a tarball. 这将占用所有现有图层,并将它们导出为tarball中的单个文件系统映像。 Then import will bring it back in again as an image. 然后导入将再次将其带回作为图像。

Steps: 脚步:

docker run --name mycontainer the image to create a container (the container name mycontainer is just an example) docker run --name mycontainer镜像创建一个容器(容器名mycontainer只是一个例子)

docker export --output=mycontainer.tar mycontainer the container to a tarball (mycontainer.tar is just an example) docker export --output=mycontainer.tar mycontainer将容器打包到tarball(mycontainer.tar只是一个示例)

cat mycontainer.tar | docker import - mynewimage:imported cat mycontainer.tar | docker import - mynewimage:imported the tarball (the image name mynewimage:imported is just an example) cat mycontainer.tar | docker import - mynewimage:imported了tar包(图像名称mynewimage:imported只是一个示例)

Docs: 文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM