新的 Docker --squash 是如何工作的 [英] How does the new Docker --squash work

查看:37
本文介绍了新的 Docker --squash 是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker 1.13 中添加了新的 --squash 参数.

In Docker 1.13 the new --squash parameter was added.

我现在希望减小图像的大小并能够隐藏"图像.我的图层中的秘密文件.

I'm now hoping to reduce the size of my images as well as being able to "hide" secret files I have in my layers.

您现在可以在下面看到使用和不使用 --squash 参数进行构建的区别.

Below you can now see the difference from doing a build with and without the --squash parameter.

没有壁球

带壁球

现在回答我的问题.

如果我在我的 first 层中添加一个秘密文件,然后在我的 第二 层中使用该秘密文件,最后在 中删除我的秘密文件第三层,然后使用 --squash 标志构建.

If I add a secret file in my first layer, then use the secret file in my second layer, and the finally remove my secret file in the third layer, and then build with the --squash flag.

现在有任何方法来获取秘密文件吗?

Will there be any way now to get the secret file?

推荐答案

如果我在第一层添加了一个秘密文件,那么在我的第二层,最后在第三层删除我的秘密文件层,然后使用 --squash 标志构建.

If I add a secret file in my first layer, then use the secret file in my second layer, and the finally remove my secret file in the third layer, and then build with the --squash flag.

现在有什么办法可以得到秘密文件吗?

Will there be any way now to get the secret file?

回答:您的图片不会有秘密文件.

--squash 的工作原理:

构建完成后,Docker 会创建一个新图像,将每个层的差异加载到一个新层中,并引用所有父层.

Once the build is complete, Docker creates a new image loading the diffs from each layer into a single new layer and references all the parent's layers.

换句话说:当压缩时,Docker 将把构建产生的所有文件系统层合并到一个新层中.

In other words: when squashing, Docker will take all the filesystem layers produced by a build and collapse them into a single new layer.

这可以简化创建最小容器图像的过程,但在移动图像时可能会导致稍高的开销(因为压缩的层不能再在图像之间共享).Docker 仍会缓存各个层以加快后续构建速度.

This can simplify the process of creating minimal container images, but may result in slightly higher overhead when images are moved around (because squashed layers can no longer be shared between images). Docker still caches individual layers to make subsequent builds fast.

请注意,此功能会将所有新建的图层压缩为一个图层,而不是挤压到划痕.

Please note this feature squashes all the newly built layers into a single layer, it is not squashing to scratch.

旁注:

Docker 1.13 还支持使用 --compress 标志压缩从 CLI 发送到守护进程的构建上下文.这将通过减少发送的数据量来加快在远程守护进程上完成的构建.

Docker 1.13 also has support for compressing the build context that is sent from CLI to daemon using the --compress flag. This will speed up builds done on remote daemons by reducing the amount of data sent.

请注意,从 Docker 1.13 开始,此功能是实验性的.

Please note as of Docker 1.13 this feature is experimental.

这篇关于新的 Docker --squash 是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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