我已经使用Dockerfile in this repo构建了一个图像,并且由于它在opencv源文件上执行了make
,因此图像大小增加了3.1 GB。 因此,为了减少图像的大小,我在安装OpenCV后删除了源代码和构建文件,并且如果检查图像的大小,它确实显示尺寸减小了,但是当我使用docker images
命令检查时,尺寸仍然是相同。“docker images”命令不显示正确的大小
下面是来自docker build
RUN echo "Size of image before installing OpenCV"
---> Using cache
---> 6408d5fde660
Step 11 : RUN echo `du -sh /`
---> Running in 70e945c95f0c
1.9G/
---> 60f80a0d27e6
Removing intermediate container 70e945c95f0c
Step 12 : RUN cd ~/ && git clone......
Step 14 : RUN echo "Size of image AFTER installing OpenCV"
---> Using cache
---> 1e065271efa7
Step 15 : RUN echo `du -sh /`
---> Running in 0f82de699dd9
5.9G/
---> a90660ac1f25
Removing intermediate container 0f82de699dd9
Step 16 : RUN echo "Size of OpenCV source and build directories"
---> Running in 7412b1e468e8
Size of OpenCV source and build directories
---> 252b6d0ef5b7
Removing intermediate container 7412b1e468e8
Step 17 : RUN echo `du -sh ~/opencv*`
---> Running in 8fddb31f4770
3.8G /root/opencv 218M /root/opencv_contrib
---> 3f9c355fec15
Removing intermediate container 8fddb31f4770
Step 18 : RUN rm -rf ~/opencv* # This removes
---> Running in 8a6c823f5675
---> 96af8b3d01bf
Removing intermediate container 8a6c823f5675
Step 19 : RUN echo "Size of image AFTER removing OpenCV source and build directories"
---> Running in e292c233f8db
Size of image AFTER removing OpenCV source and build directories
---> b08582019c1b
Removing intermediate container e292c233f8db
Step 20 : RUN echo `du -sh ~/opencv*`
---> Running in 9cb62f3be3b3
du: cannot access '/root/opencv*': No such file or directory
---> 74473a783265
Removing intermediate container 9cb62f3be3b3
Step 21 : RUN echo `du -sh /`
---> Running in 45c9fcedf650
1.9G/
---> 0350a13a1a3b
Removing intermediate container 45c9fcedf650
Successfully built 0350a13a1a3b
输出从最后一步,它看起来像图像的大小应该是1.9GB,但是当我做docker images
它让我看到6.298 GB
➜ d1 docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu_py latest 0350a13a1a3b 11 seconds ago 6.298 GB
即使是容器尺寸正确显示,
➜ d1 docker run -it ubuntu_py /bin/bash
[email protected]:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[email protected]:/# du -sh
1.9G .
[email protected]:/#
是否仅为此特定图像注意到尺寸偏差?对于不同的图像呢?你使用什么码头版本? “码头检查”显示了什么?相同的尺寸? – Rao