Dockerfile中的命令数 [英] Number of commands in Dockerfile
问题描述
如果我们尝试做一个的命令行运行cmd1&& cmd2&& cmd3
?
如果我们使用像Quay这样的服务,会有什么不同?
谢谢!
作为 Alister说,如果您使用AUFS文件系统,则Docker映像中的层数有上限。 在Docker版本0.7.2的限制被提升到127层( changelog )。
由于这是底层联合文件系统的限制(在AUFS的情况下) ,使用码头或其他私人登记册不会改变结果。但是您可以使用不同的文件系统。
目前的替代文件系统是使用 devicemapper
(请参阅 CLI文档)。这些其他文件系统可能对层数有不同的限制 - 我不认为devicemapper有一个上限。
你是对的,通过运行多个命令单一的RUN语句,可以减少层数。
或者,如果您真的需要大量图层来构建图像,则可以构建图像,直到它达到最大值,然后使用 docker export
创建图像文件系统的不分层副本。然后, docker import
再次将其重新映射成图像,此时只需一层,然后继续构建。你失去了这种历史。
I noticed that each line in the Dockerfile creates a separate image. Is there any limit on the number of images that are created?
Should we try to do a oneliner of RUN cmd1 && cmd2 && cmd3
instead?
How would this differ if we use a service like Quay?
Thanks!
As Alister said, there is an upper limit on the number of layers in a Docker image if you are using the AUFS file system. At Docker version 0.7.2 the limit was raised to 127 layers (changelog).
Since this a limitation of the underlying union file system (in the case of AUFS), using Quay or other private registries won't change the outcome. But you could use a different file system.
The current alternative filesystem is to use devicemapper
(see CLI docs). These other filesystems may have different limitations on the number of layers -- I don't think devicemapper has an upper limit.
You're right, by RUNning multiple commands in a single RUN statement, you can reduce the number of layers.
Alternatively, if you really need a lot of layers to build your image, you could build an image until it reaches the maximum and then use docker export
to create an un-layered copy of the image's file system. Then docker import
to turn it back into an image again, this time with just one layer, and continue building. You lose the history that way though.
这篇关于Dockerfile中的命令数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!