我正在尝试从debian:latest
构建图像。构建后,从docker images
命令报告的图像虚拟大小为1.917 GB。我登录后检查了大小(du -sh /
),它的大小为573 MB。我敢肯定,这种大尺寸通常是不可能的。这里发生了什么?如何获得正确的图像尺寸?更重要的是,当我推送此存储库时,其大小为1.9 GB,而不是573 MB。
du -sh /*
的输出
8.9M /bin
4.0K /boot
0 /dev
1.1M /etc
4.0K /home
30M /lib
4.0K /lib64
4.0K /media
4.0K /mnt
4.0K /opt
du: cannot access '/proc/11/task/11/fd/4': No such file or directory
du: cannot access '/proc/11/task/11/fdinfo/4': No such file or directory
du: cannot access '/proc/11/fd/4': No such file or directory
du: cannot access '/proc/11/fdinfo/4': No such file or directory
0 /proc
427M /root
8.0K /run
3.9M /sbin
4.0K /srv
0 /sys
8.0K /tmp
88M /usr
15M /var
最佳答案
1.9GB的大小不是图像,而是图像及其历史记录。使用docker history textbox
检查占用了这么多空间的内容。
另请参阅Why are Docker container images so large?
为了减小大小,您可以更改构建镜像的方式(这取决于您的工作,请从上面的链接中查看答案),使用docker export(请参阅How to flatten a Docker image?)或使用other extensions。
关于linux - docker容器大小比实际大小大得多,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31627772/