我已經使用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