构建docker映像会导致大小翻倍

时间:2019-05-25 11:22:16

标签: docker dockerfile

因此,我试图通过多阶段构建过程制作最小的图像,并且全部解决了,但是图像大小似乎不正确。

最终图像的docker历史记录输出

IMAGE                                                                     CREATED             CREATED BY                                                                                                                      SIZE                COMMENT
sha256:1d430f8b3479c874ceaf6f2a3082ee6c6e726fe22dcd1bf8d2c3cfbfe72468a0   About an hour ago   /bin/sh -c #(nop)  CMD ["-config_path" "/config"]                                                                               0B                  
sha256:c25fee5c87edeec529335df9daf093760c5d2e9fdda258005f9743605b0db26c   About an hour ago   /bin/sh -c #(nop)  ENTRYPOINT ["/cgrates/cgr-engine"]                                                                           0B                  
sha256:e5ee2c63bccd8b5cd6b7caf2833c0c4ea54dafad5682225717009808d38222a0   About an hour ago   /bin/sh -c #(nop)  VOLUME [/config]                                                                                             0B                  
sha256:2ddc0dd3af71acfab190544aa45711b3dbdb285124565196c1d05bfde3bde867   About an hour ago   /bin/sh -c #(nop)  USER cgrates                                                                                                 0B                  
sha256:45d1598dfdc1e732f75c015214a977fe70f7eb955709ec86b122c18c72574408   About an hour ago   /bin/sh -c adduser -g '' -h /cgrates -u 1000 -D -s /sbin/nologin cgrates     && chown -R cgrates:cgrates /cgrates               42.1MB              
sha256:36832f92c349d9d8645fd6bd5a3437d9a07bca68c92307b802e90fb7f7cf2259   About an hour ago   /bin/sh -c #(nop) COPY file:ed9cb788bbfeacad1ce67440fe6388609cf6c6d7df5be16d5a3145a74a3230ba in /cgrates/cgr-engine             42.1MB              
sha256:c6ad53011db71285780f8032fcf0754db4007eb75a79edd4794fa6738cde0372   About an hour ago   /bin/sh -c #(nop)  LABEL author=john doe john@example.com desc=cgrates master/latest git version at time of build   0B                  
sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1   2 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]                                                                                              0B                  
<missing>                                                                 2 weeks ago         /bin/sh -c #(nop) ADD file:a86aea1f3a7d68f6ae03397b99ea77f2e9ee901c5c59e59f76f93adbb4035913 in /                                5.53MB              

我希望在 adduser 步骤中多出几个字节,但不会再增加42.1MB,就好像我两次执行复制步骤一样

1 个答案:

答案 0 :(得分:1)

您正在更改在上一步中复制到容器中的所有文件。对于Docker来说,这些都是全新文件,因此您得到的大小是预期的两倍。

在复制文件时,尝试使用COPY --chown=cgrates:cgrates . /cgrates/cgr-engine更改所有者,以防止这种情况。另外,您需要先创建用户,然后才能复制文件。