我用这个Dockerfile构建一个图像。
FROM sanmingzi/ruby:1.9.3
RUN yum -y install gcc ruby-devel zlib-devel \
&& yum -y remove gcc ruby-devel zlib-devel \
&& yum -y clean all \
&& rm -rf /var/cache/yum \
&& rm -rf /var/tmp/*
我希望新图像的大小与sanmingzi / ruby相同:1.9.3,但我错了。比旧图像大约50MB。我使用docker history
来显示详细信息。
IMAGE CREATED CREATED BY SIZE
b154156f1053 4 minutes ago /bin/sh -c yum -y install gcc ruby-devel z... 55.4MB
答案 0 :(得分:0)
当我们在CentOS映像中安装gcc
,ruby-devel
和zlib-devel
时,还会安装或升级许多其他依赖包:
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
gcc x86_64 4.8.5-16.el7_4.2 updates 16 M
ruby-devel x86_64 2.0.0.648-33.el7_4 updates 131 k
Installing for dependencies:
cpp x86_64 4.8.5-16.el7_4.2 updates 6.0 M
glibc-devel x86_64 2.17-196.el7_4.2 updates 1.1 M
glibc-headers x86_64 2.17-196.el7_4.2 updates 676 k
kernel-headers x86_64 3.10.0-693.21.1.el7 updates 6.0 M
libgomp x86_64 4.8.5-16.el7_4.2 updates 154 k
libmpc x86_64 1.0.1-3.el7 base 51 k
mpfr x86_64 3.1.1-4.el7 base 203 k
ruby x86_64 2.0.0.648-33.el7_4 updates 71 k
ruby-irb noarch 2.0.0.648-33.el7_4 updates 92 k
ruby-libs x86_64 2.0.0.648-33.el7_4 updates 2.8 M
rubygem-bigdecimal x86_64 1.2.0-33.el7_4 updates 83 k
rubygem-io-console x86_64 0.4.2-33.el7_4 updates 54 k
rubygem-json x86_64 1.7.7-33.el7_4 updates 79 k
rubygem-psych x86_64 2.0.0-33.el7_4 updates 82 k
rubygem-rdoc noarch 4.0.0-33.el7_4 updates 322 k
rubygems noarch 2.0.14.1-33.el7_4 updates 219 k
Updating for dependencies:
libgcc x86_64 4.8.5-16.el7_4.2 updates 98 k
Transaction Summary
================================================================================
Install 2 Packages (+16 Dependent packages)
Upgrade ( 1 Dependent package)
然后我们只删除gcc
,ruby-devel
和zlib-devel
:
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
gcc x86_64 4.8.5-16.el7_4.2 @updates 37 M
ruby-devel x86_64 2.0.0.648-33.el7_4 @updates 337 k
zlib-devel x86_64 1.2.7-17.el7 @base 132 k
Removing for dependencies:
openssl-devel x86_64 1:1.0.2k-8.el7 @base 3.1 M
Transaction Summary
================================================================================
Remove 3 Packages (+1 Dependent package)
这就是为什么我们的最终图像尺寸比原始图像大。