最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

docker鏡像壓縮squash的實(shí)現(xiàn)

 更新時(shí)間:2023年07月04日 10:43:28   作者:岳來(lái)  
本文主要介紹了docker鏡像壓縮squash的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

docker build 通過(guò)Dockerfile 制作鏡像會(huì)根據(jù)命令形成一層層layer,這樣造成文件重復(fù),鏡像體積比較大;為了縮小層的數(shù)量及其大小,能夠像壓縮git commit一樣壓縮layer層,docker-squash能夠執(zhí)行此操作。Docker squash將壓縮多個(gè)鏡像layer層,以便刪除存儲(chǔ)在兩頭步驟中的所有數(shù)據(jù),即刪除掉重復(fù)數(shù)據(jù)。本文就docker-squash 使用效果展開(kāi)討論。

一、docker-squash 安裝

pip install docker-squash
docker-squash --help
usage: docker-squash [-h] [-v] [--version] [-d] [-f FROM_LAYER] [-t TAG]
? ? ? ? ? ? ? ? ? ? ?[-m MESSAGE] [-c] [--tmp-dir TMP_DIR]
? ? ? ? ? ? ? ? ? ? ?[--output-path OUTPUT_PATH]
? ? ? ? ? ? ? ? ? ? ?image
Docker layer squashing tool
positional arguments:
? image ? ? ? ? ? ? ? ? Image to be squashed
optional arguments:
? -h, --help ? ? ? ? ? ?show this help message and exit
? -v, --verbose ? ? ? ? Verbose output
? --version ? ? ? ? ? ? Show version and exit
? -d, --development ? ? Does not clean up after failure for easier debugging
? -f FROM_LAYER, --from-layer FROM_LAYER
? ? ? ? ? ? ? ? ? ? ? ? Number of layers to squash or ID of the layer (or
? ? ? ? ? ? ? ? ? ? ? ? image ID or image name) to squash from. In case the
? ? ? ? ? ? ? ? ? ? ? ? provided value is an integer, specified number of
? ? ? ? ? ? ? ? ? ? ? ? layers will be squashed. Every layer in the image will
? ? ? ? ? ? ? ? ? ? ? ? be squashed if the parameter is not provided.
? -t TAG, --tag TAG ? ? Specify the tag to be used for the new image. If not
? ? ? ? ? ? ? ? ? ? ? ? specified no tag will be applied
? -m MESSAGE, --message MESSAGE
? ? ? ? ? ? ? ? ? ? ? ? Specify a commit message (comment) for the new image.
? -c, --cleanup ? ? ? ? Remove source image from Docker after squashing
? --tmp-dir TMP_DIR ? ? Temporary directory to be created and used
? --output-path OUTPUT_PATH
? ? ? ? ? ? ? ? ? ? ? ? Path where the image should be stored after squashing.
? ? ? ? ? ? ? ? ? ? ? ? If not provided, image will be loaded into Docker
? ? ? ? ? ? ? ? ? ? ? ? daemon

二、使用介紹

2.1、部分壓縮指定層數(shù)

首先docker history查看鏡像層數(shù)

docker history java:3.0
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
63a1b1edb376        4 weeks ago         /bin/sh -c #(nop)  LABEL ImageName=reg.docke…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseRootfsLayerCoun…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseLayerCount=25      0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL baseOS=reg.docker.a…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  VOLUME [/home/admin/logs]    0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENTRYPOINT ["/bin/sh" "-c…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENV JVM_Xms= JVM_Xmx= JVM…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENV JAVA_HOME=/opt/taobao…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENV LANG=zh_CN.utf8          0B                  
<missing>           4 weeks ago         /bin/sh -c [[ $(uname -p) != "sw_64" ]] && r…   97MB                
<missing>           4 weeks ago         /bin/sh -c yum clean --enablerepo=* all;    …   628MB               
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY file:cbad11e2b6b88c38…   19.9MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY file:fd3bca1e9167d639…   21MB                
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:2761dc242787e3ab8…   39.2MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:8a9faa49606db326b…   8.49MB              
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL ImageName=reg.docke…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseRootfsLayerCoun…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseLayerCount=10      0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL baseOS=reg.docker.a…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENTRYPOINT [""]              0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  CMD ["/sbin/init"]           0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:61a850de6501dac7b…   3.03kB              
<missing>           4 weeks ago         /bin/sh -c sed -i -e 's/root:[^:]*:/root:*:/…   94.6MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:ca4e72cff3459ccab…   395B                
<missing>           16 months ago                                                       282MB               Imported from -

使用dive 工具查看鏡像效率參數(shù)

CI=true dive java:3.0
  Using default CI config
Image Source: docker://java:3.0
Fetching image... (this can take a while for large images)
Analyzing image...
  efficiency: 78.5919 %
  UserSizeByes: 90775433100 bytes (908 MB)
  SizeByes: 118928447300 bytes (1.2 GB)
  wastedBytes: 381696817 bytes (382 MB)
  userWastedPercent: 42.0485 %
Inefficient Files:
Count  Wasted Space  File Path
    2        119 MB  /usr/lib/locale/locale-archive
    ...
    2           0 B  /usr/lib/systemd/system/runlevel0.target
Results:
  FAIL: highestUserWastedPercent: too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.4204847104166557 > threshold=0.1)
  SKIP: highestWastedBytes: rule disabled
  FAIL: lowestEfficiency: image efficiency is too low (efficiency=0.7859187397531037 < threshold=0.9)
Result:FAIL [Total:3] [Passed:0] [Failed:2] [Warn:0] [Skipped:1

命令格式

docker-squash -f <層數(shù),依據(jù)docker history> -t 新鏡像名稱(chēng) 原鏡像名稱(chēng)

如下:

docker-squash -f 11 -t java-squash-11:1.0 java:3.0
2023-01-20 13:41:43,978 root         INFO     docker-squash version 1.0.10, Docker 5138787, API 1.39...
2023-01-20 13:41:43,978 root         INFO     Using v2 image format
2023-01-20 13:41:43,982 root         INFO     Old image has 25 layers
2023-01-20 13:41:43,982 root         INFO     Checking if squashing is necessary...
2023-01-20 13:41:43,982 root         INFO     Attempting to squash last 11 layers...
2023-01-20 13:41:43,982 root         INFO     Saving image sha256:63a1b1edb376fb12838dbbef7749effc1e8e6a973d33a47aee194eff6a173edd to /tmp/docker-squash-OlTnlF/old directory...
2023-01-20 13:42:03,134 root         INFO     Image saved!
2023-01-20 13:42:03,135 root         INFO     Squashing image 'java:3.0'...
2023-01-20 13:42:03,136 root         INFO     Starting squashing...
2023-01-20 13:42:03,870 root         INFO     Squashing file '/tmp/docker-squash-OlTnlF/old/ddf4a6e4ea15a7ca3825c70e116e40f3a01f25b7df008d4517c826ef78c03dc8/layer.tar'...
2023-01-20 13:42:06,729 root         INFO     Squashing file '/tmp/docker-squash-OlTnlF/old/7be6dcb4742458db7e2c77fb1ad9fd66555e6f08d28c74592a9b973740356919/layer.tar'...
2023-01-20 13:42:19,510 root         INFO     Squashing finished!
2023-01-20 13:42:22,736 root         INFO     Original image size: 1166.43 MB
2023-01-20 13:42:22,736 root         INFO     Squashed image size: 1153.64 MB
2023-01-20 13:42:22,736 root         INFO     Image size decreased by 1.10 %
2023-01-20 13:42:22,736 root         INFO     New squashed image ID is 794121cd589230285a51d969aac97c5e936d732b0feefe5c05e78b027e850312
2023-01-20 13:42:30,244 root         INFO     Image registered in Docker daemon as java-squash-11:1.0
2023-01-20 13:42:30,369 root         INFO     Done

壓縮后體積如下:

docker images | grep java
java-squash-11       1.0            794121cd5892        About a minute ago   1.17GB
java                 3.0            63a1b1edb376        4 weeks ago          1.19GB

再次查看history

docker history java-squash-11:1.0
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
794121cd5892        5 minutes ago                                                       703MB               
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY file:cbad11e2b6b88c38…   19.9MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY file:fd3bca1e9167d639…   21MB                
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:2761dc242787e3ab8…   39.2MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:8a9faa49606db326b…   8.49MB              
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL ImageName=reg.docke…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseRootfsLayerCoun…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL BaseLayerCount=10      0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  LABEL baseOS=reg.docker.a…   0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  ENTRYPOINT [""]              0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop)  CMD ["/sbin/init"]           0B                  
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:61a850de6501dac7b…   3.03kB              
<missing>           4 weeks ago         /bin/sh -c sed -i -e 's/root:[^:]*:/root:*:/…   94.6MB              
<missing>           4 weeks ago         /bin/sh -c #(nop) COPY dir:ca4e72cff3459ccab…   395B                
<missing>           16 months ago                                                       282MB               Imported from -

再次dive 分析,鏡像效率參數(shù)有些許改觀

CI=true dive java-squash-11:1.0
  Using default CI config
Image Source: docker://java-squash-11:1.0
Fetching image... (this can take a while for large images)
Analyzing image...
  efficiency: 79.9717 %
  UserSizeByes: 88655803400 bytes (887 MB)
  SizeByes: 116808817600 bytes (1.2 GB)
  wastedBytes: 360500520 bytes (360 MB)
  userWastedPercent: 40.6629 %
Inefficient Files:
Count  Wasted Space  File Path
    2        119 MB  /usr/lib/locale/locale-archive
    ...
    2           0 B  /usr/lib/systemd/system/sysinit.target.wants/cryptsetup.target
Results:
  FAIL: highestUserWastedPercent: too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.40662935326803434 > threshold=0.1)
  SKIP: highestWastedBytes: rule disabled
  FAIL: lowestEfficiency: image efficiency is too low (efficiency=0.7997167019774828 < threshold=0.9)
Result:FAIL [Total:3] [Passed:0] [Failed:2] [Warn:0] [Skipped:1]

2.2、完全壓縮

即壓縮成一層

docker-squash -f 25  -t java-squash-all:1.0 java:3.0
2023-01-20 13:53:47,397 root         INFO     docker-squash version 1.0.10, Docker 5138787, API 1.39...
2023-01-20 13:53:47,397 root         INFO     Using v2 image format
2023-01-20 13:53:47,401 root         INFO     Old image has 25 layers
2023-01-20 13:53:47,401 root         INFO     Checking if squashing is necessary...
2023-01-20 13:53:47,401 root         INFO     Attempting to squash last 25 layers...
2023-01-20 13:53:47,401 root         INFO     Saving image sha256:63a1b1edb376fb12838dbbef7749effc1e8e6a973d33a47aee194eff6a173edd to /tmp/docker-squash-23fgk8/old directory...
2023-01-20 13:54:06,767 root         INFO     Image saved!
2023-01-20 13:54:06,767 root         INFO     Squashing image 'java:3.0'...
2023-01-20 13:54:06,768 root         INFO     Starting squashing...
2023-01-20 13:54:06,768 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/ddf4a6e4ea15a7ca3825c70e116e40f3a01f25b7df008d4517c826ef78c03dc8/layer.tar'...
2023-01-20 13:54:09,616 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/7be6dcb4742458db7e2c77fb1ad9fd66555e6f08d28c74592a9b973740356919/layer.tar'...
2023-01-20 13:54:20,751 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/57be802a5ecce1545d1fef09e3f0b04cef12386e3995b8f98b827c1fa690f2dc/layer.tar'...
2023-01-20 13:54:20,778 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/e113fadd42d1969d71a6d30cf402938436e9aba0de9af3ed2cdacec9e1842103/layer.tar'...
2023-01-20 13:54:20,799 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/eca237f8359a3c25227be27fd27ebff05b510f06b9768639e3484741d9995073/layer.tar'...
2023-01-20 13:54:20,809 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/2a47dbd3a252894e057a55d676f92625d24bfc8ad10a28b008e8b87638480ee6/layer.tar'...
2023-01-20 13:54:20,871 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/bb207541a62d1cf5aa5dc13e971301949a22d2c3016e317d2190f1b51bde0167/layer.tar'...
2023-01-20 13:54:20,876 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/354eb0981c6f10dcf5744386501d61c670f5bfbf77063c778b26e5c0450543f3/layer.tar'...
2023-01-20 13:54:22,489 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/e31074992543d56a24b7da3457af34c7df7439ced6d9c0bf72ce4122fc380d81/layer.tar'...
2023-01-20 13:54:22,492 root         INFO     Squashing file '/tmp/docker-squash-23fgk8/old/1641651324846664fa3c233e4459767551e4ab9f081a718085216d30687e0877/layer.tar'...
2023-01-20 13:54:52,084 root         INFO     Squashing finished!
2023-01-20 13:54:54,922 root         INFO     Original image size: 1166.43 MB
2023-01-20 13:54:54,922 root         INFO     Squashed image size: 981.28 MB
2023-01-20 13:54:54,922 root         INFO     Image size decreased by 15.87 %
2023-01-20 13:54:54,923 root         INFO     New squashed image ID is f508f38322ae8950e49bd8cbcf140356dd236654ecd6bf303440d93081f6f7c9
2023-01-20 13:55:04,532 root         INFO     Image registered in Docker daemon as java-squash-all:1.0
2023-01-20 13:55:04,624 root         INFO     Done

docker history 查看

docker history java-squash-all:1.0
IMAGE          CREATED              CREATED BY          SIZE                COMMENT
f508f38322ae   About a minute ago                       989MB               

docker images 比較一下大小

docker images | grep java
java-squash-all       1.0                 f508f38322ae        30 minutes ago      989MB
java-squash-11        1.0                 794121cd5892        42 minutes ago      1.17GB
java                  3.0                 63a1b1edb376        4 weeks ago         1.19GB

dive 分析

CI=true dive java-squash-all:1.0
  Using default CI config
Image Source: docker://java-squash-all:1.0
Fetching image... (this can take a while for large images)
Analyzing image...
  efficiency: 100.0000 %
  UserSizeByes: 0 bytes (0 B)
  SizeByes: 98904607400 bytes (989 MB)
  wastedBytes: 0 bytes (0 B)
  userWastedPercent: NaN %
Inefficient Files:
Count  Wasted Space  File Path
None
Results:
  PASS: highestUserWastedPercent
  SKIP: highestWastedBytes: rule disabled
  PASS: lowestEfficiency
Result:PASS [Total:3] [Passed:2] [Failed:0] [Warn:0] [Skipped:1]

三、總結(jié)

1、docker-squash 根據(jù)docker history 層數(shù)對(duì)鏡像進(jìn)行壓縮
2、-f 指定的層數(shù)越大,壓縮效率越好
3、結(jié)合dive 工具,更直觀展示壓縮效率
4、壓縮后的圖像可以加載回Docker守護(hù)進(jìn)程,即可以通過(guò)docker images 查看
5、使用docker-squash 也存在缺點(diǎn),壓縮為一層時(shí)無(wú)法根據(jù)docker history查看鏡像構(gòu)建歷史。

參考文檔

1、https://lequ7.com/guan-yu-docker-chuang-jian-zui-xiao-hua-de-rong-qi-jing-xiang-er.html
2、https://mp.weixin.qq.com/s/S1Ib08SpQbf1SCbCutUoqQ
3、https://blog.csdn.net/j_starry/article/details/125185506
4、https://github.com/jwilder/docker-squash
5、https://bbs.huaweicloud.com/blogs/336684
6、https://github.com/dive/
7、https://www.cnpython.com/pypi/docker-squash
8、https://cloud.tencent.com/developer/article/1444954

到此這篇關(guān)于docker鏡像壓縮squash的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)docker squash內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

  • Docker配置容器位置與小技巧總結(jié)

    Docker配置容器位置與小技巧總結(jié)

    這篇文章主要給大家介紹了關(guān)于Docker配置容器位置與小技巧的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Docker具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Docker 教程之鏡像列出詳細(xì)介紹

    Docker 教程之鏡像列出詳細(xì)介紹

    這篇文章主要介紹了Docker 教程之鏡像列出詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • docker在ubuntu14.04下的安裝步驟

    docker在ubuntu14.04下的安裝步驟

    這篇文章主要介紹了docker在ubuntu14.04下的安裝步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • docker.service啟動(dòng)報(bào)錯(cuò)的一次排查詳解

    docker.service啟動(dòng)報(bào)錯(cuò)的一次排查詳解

    這篇文章主要介紹了docker.service啟動(dòng)報(bào)錯(cuò)的一次排查詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 在docker容器中使用非root用戶(hù)執(zhí)行腳本操作

    在docker容器中使用非root用戶(hù)執(zhí)行腳本操作

    這篇文章主要介紹了在docker容器中使用非root用戶(hù)執(zhí)行腳本操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 如何在Docker容器內(nèi)外互相拷貝數(shù)據(jù)

    如何在Docker容器內(nèi)外互相拷貝數(shù)據(jù)

    本篇文章主要介紹了如何在Docker容器內(nèi)外互相拷貝數(shù)據(jù),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • docker容器/etc/hosts文件修改方法

    docker容器/etc/hosts文件修改方法

    在容器內(nèi)部,當(dāng)需要訪問(wèn)其他容器或主機(jī)時(shí),可以通過(guò)/etc/hosts文件來(lái)解析主機(jī)名,從而實(shí)現(xiàn)網(wǎng)絡(luò)通信,這篇文章主要介紹了docker容器/etc/hosts文件,需要的朋友可以參考下
    2023-06-06
  • Docker Namespace容器隔離的實(shí)現(xiàn)

    Docker Namespace容器隔離的實(shí)現(xiàn)

    Namespace是Docker容器中的一種隔離機(jī)制,通過(guò)劃分資源獨(dú)立空間,確保容器之間互不干擾,本文主要介紹一下Docker Namespace容器隔離的實(shí)現(xiàn),感興趣的可以了解一下
    2024-11-11
  • Docker?Compose資源配額管理實(shí)現(xiàn)限制容器CPU與內(nèi)存使用

    Docker?Compose資源配額管理實(shí)現(xiàn)限制容器CPU與內(nèi)存使用

    在容器化部署中,資源競(jìng)爭(zhēng)是最常見(jiàn)的穩(wěn)定性隱患,當(dāng)一個(gè)服務(wù)異常占用CPU或內(nèi)存時(shí),可能導(dǎo)致整個(gè)應(yīng)用集群異常,本文將系統(tǒng)講解Docker?Compose的資源配額管理方案,感興趣的可以了解一下
    2026-04-04
  • Docker容器的Tengine實(shí)踐

    Docker容器的Tengine實(shí)踐

    Tengine是淘寶開(kāi)發(fā)的基于nginx的應(yīng)用服務(wù)器,反向代理服務(wù)器。它兼容nginx的所有配置,并且在其上增加了很多實(shí)用的功能,例如動(dòng)態(tài)模塊加載,集成lua語(yǔ)言進(jìn)行擴(kuò)展等,在性能方面有了比較大的改進(jìn)。今天我們來(lái)看下在Docker下如何部署
    2016-06-06

最新評(píng)論

辽阳市| 乐清市| 南江县| 丹东市| 翁源县| 遂溪县| 温宿县| 浏阳市| 左云县| 庄浪县| 深圳市| 米脂县| 遂溪县| 香河县| 红桥区| 杭锦后旗| 义马市| 丹寨县| 泌阳县| 民丰县| 师宗县| 丹东市| 磐石市| 子长县| 博兴县| 新泰市| 布尔津县| 晋宁县| 福清市| 翁源县| 砚山县| 巴南区| 九江县| 射阳县| 鄂尔多斯市| 漳平市| 齐齐哈尔市| 沁阳市| 忻城县| 新疆| 堆龙德庆县|