I am using docker to analyse changes to the file system caused by various commands. I simply add relevant RUN
lines in the Dockerfile
, build it, use docker save
to see what changes were made. Unfortunately I use many commands, end even though most of the time I can put several of them into one layer, I usually exceed the rather low 127 parent layers limit.
To deal with this I squish images with many layers into images with just one layer, and use the resulting image as the parent for the rest of the new layers. The best way to do that is to spin up a container and then use docker export
, and then to docker import
that to get a nice single layer of changes. I am looking for ways to shave down the time it takes to perform that operation.
Is there a simple way to do the same thing (export the fully expanded file system of an image, not just the layers stack as in docker save
) without spinning up a container?
答案 0 :(得分:3)
无论采用何种方法,压缩整个容器始终是一个读取分层文件系统并编写新的平面文件系统的过程,这涉及到相对较慢的io。
相比之下,创建一个容器的重量非常轻,所以我不确定你会通过摆脱这个步骤获得多少收益
time container=$(docker create debian)
time docker export $container | docker import - debian_flat
time docker rm $container
在基于ssd的系统上,结果为:
创建
real 0m0.050s
user 0m0.015s
sys 0m0.010s
导出/导入
real 0m8.213s
user 0m2.867s
sys 0m0.768s
删除
real 0m0.019s
user 0m0.007s
sys 0m0.008s
还有其他工具可以you squash selected layers。这可以节省您的时间,因为您只需要读取和写入一部分数据。如果您的要求是挤压完整的图像,那么我不确定这将比导出/导入快得多,因为您仍在读取和写入相同数量的数据。
有github issue来覆盖官方泊坞窗中的壁球功能,而pull requests覆盖support以直接挤压或压平泊坞窗和构建中的图层。在接受之前,每个请求似乎都会慢慢消失。