简体   繁体   English

即使进行了清理,Dockerfile RUN 也会创建一个胖层

[英]Dockerfile RUN creates a fat layer even with cleanup

It's generally understood that if the RUN instruction cleans up after large file operations, the resulting layer size would be smaller.一般的理解是,如果RUN指令在大文件操作后进行清理,得到的层大小会更小。 However when I execute the following script the resulting layer is large and roughly corresponds to the size of the files initially copied and cleaned.但是,当我执行以下脚本时,生成的图层很大,大致对应于最初复制和清理的文件的大小。

How could this size of a layer be committed if the files copied are cleaned in the same layer?如果复制的文件在同一层中清除,那么如何提交这种大小的层?

RUN mkdir -p /etc/puppet && \
    cd /etc/puppet && \
    apt-get update && apt-get install -y wget puppet && \
    wget -rnH --level=10 -e robots=off --reject "index.html*" http://somefileserver.org/puppet/allpuppetstuff && \
    puppet module install puppetlabs/stdlib && \
    puppet module install 7terminals-java && \
    puppet apply -e "include someserver" && \
    apt-get purge -y --auto-remove puppet wget && \
    rm -rfv /etc/puppet/* && \
    rm -rfv /var/lib/apt/lists/*

Found some details after few tweaks.经过几次调整后发现了一些细节。

It seems docker duplicates on old layer, if a newer layer is modifying files persisted on the earlier one.如果较新的层正在修改保留在较早层上的文件,则 docker 似乎在旧层上重复。 This is the cause of the fat layer created by the above RUN command, even when the total file size diff at the end of operation is minimal.这就是上面 RUN 命令创建的胖层的原因,即使在操作结束时总文件大小差异很小。 I couldn't find any definite resources to cite this, but this is the experience so far.我找不到任何明确的资源来引用这一点,但这是迄今为止的经验。

Basically, file operations related to the image should always be done in one layer.基本上,与图像相关的文件操作应该始终在一层中完成。

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

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