简体   繁体   English

docker的缺点--squash

[英]Disadvantages of docker --squash

I wanted to know about the disadvantages of docker --squash in a production environment.我想知道docker --squash在生产环境中的缺点。 The reason why I am using this command is: I needed dependencies(gcc,make,autoconf, etc) to build my PHP-react project.我使用此命令的原因是:我需要依赖项(gcc、make、autoconf 等)来构建我的 PHP-react 项目。 Also, I have created my own PHP base image which gives me these packages.此外,我还创建了自己的 PHP 基本映像,它为我提供了这些包。 Now, the problem is I want to uninstall these dependencies once my project is built.现在,问题是我想在构建项目后卸载这些依赖项。 I tried adding a RUN apt-get remove gcc make command at the end of Dockerfile but as this will be a separate layer from where these dependencies were installed, the overall size of the docker image remains the same.我尝试在 Dockerfile 的末尾添加一个RUN apt-get remove gcc make命令,但由于这将是安装这些依赖项的单独层,因此 docker 图像的整体大小保持不变。 I found about the docker --squash which will merge all layers into 1 layer and I have achieved ~33% space reduction.我发现 docker --squash 会将所有层合并为一层,我已经实现了约 33% 的空间减少。 But the problem is I can't use the docker squash command with docker-compose and also I don't understand if there are any performance issues or other disadvantages of using docker --squash in production.但问题是我不能将 docker squash 命令与 docker-compose 一起使用,而且我不明白在生产中使用docker --squash是否存在任何性能问题或其他缺点。

I got to know about multi stage build but this is not same as I don't know which files I should not be copying in order to remove those dependencies.我开始了解多阶段构建,但这与我不知道不应该复制哪些文件以删除这些依赖项不同。 And also there will be lot of directories to be copied if I use multi-stage build如果我使用多阶段构建,也会有很多目录要复制

Thanks!谢谢!

I think they've provided the pros and the cons in its own document clearly.我认为他们已经在自己的文档中清楚地提供了优缺点。

Pro:亲:

  • Squashing layers can be beneficial if your Dockerfile produces multiple layers modifying the same files, for example, files that are created in one step, and removed in another step.如果您的 Dockerfile 生成修改相同文件的多个图层,例如,在一个步骤中创建并在另一步骤中删除的文件,则压缩图层可能是有益的。

Con:缺点:

  • The --squash option is an experimental feature, and should not be considered stable. --squash选项是一项实验性功能,不应被认为是稳定的。

  • Squashing images may actually have a negative impact on performance;压缩图像实际上可能会对性能产生负面影响; when pulling an image consisting of multiple layers, layers can be pulled in parallel, and allows sharing layers between images (saving space).拉取包含多个图层的图像时,可以并行拉取图层,并允许图像之间共享图层(节省空间)。

Alternatively或者

  • For most use cases, multi-stage builds are a better alternative, as they give more fine-grained control over your build, and can take advantage of future optimizations in the builder.对于大多数用例,多阶段构建是更好的选择,因为它们可以对您的构建进行更细粒度的控制,并且可以利用构建器中的未来优化。 Refer to the use multi-stage builds section in the userguide for more information.有关详细信息,请参阅用户指南中的使用多阶段构建部分。

See the documentation 查看文档

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

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