简体   繁体   English

dockerfile和COPY命令数

[英]dockerfile and number of COPY commands

Is there a practical difference and preferable option between: 两者之间是否有实际区别和更可取的选择:

COPY folderOrFile1 /app/folderOrFile1
COPY folderOrFile2 /app/folderOrFile2
....    
COPY folderOrFile10 /app/folderOrFile10

vs VS

COPY folderOrFile1 folderOrFile2 ... folderOrFile10  /app/

In docker each COPY command creates a layer, so is there a real reason to try to minimize the number of COPY commands and layers in this particular case? 在docker中,每个COPY命令都会创建一个图层,那么在这种特殊情况下,是否有真正的理由尝试尽量减少COPY命令和图层的数量?

Personally I prefer to do a: 我个人更喜欢这样做:

COPY app/ /app/

when possible, and have all the folders organized how I want them in the build context. 在可能的情况下,让所有文件夹按照我在构建上下文中的需要进行组织。 It's more maintainable for me and makes the Dockerfile easier to read. 它对我来说更易于维护,并且使Dockerfile易于阅读。

With your two options, there's not a huge difference. 使用您的两个选择,并没有太大的区别。 As long as each layer is independent of each other, the image size won't show a noticeable increase to have multiple layers. 只要每一层都彼此独立,则具有多层的图像大小不会显示出明显的增加。

It is good to reduce the number of layers in general to avoid the limits. 通常最好减少层数以避免限制。 But you'd need to be doing a lot of other things to the image to hit that limit, or have a large number of COPY commands, to hit those limits. 但是,您需要对映像执行很多其他操作才能达到该限制,或者要使用大量COPY命令才能达到这些限制。 Aufs with it's 42 layer limit is being phased out in favor of overlay2 which has up to 128 layers in it's limit. 具有42层限制的Aufs正在逐步淘汰,而overlay2的上限为128层。 You could see a minor performance impact from lots of layers as the filesystem driver needs to search each layer for a read operation. 由于文件系统驱动程序需要在每一层中搜索读取操作,因此您可能会看到许多层对性能的轻微影响。 So fewer is better, but more so when you get to the extremes. 因此,越少越好,但是当您走到极端时,越多越好。

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

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