docker 2、优化docker镜像大小方法

本文介绍了如何查看Docker镜像的ID及分层情况,并通过`docker history`命令分析镜像大小。重点在于通过合并`RUN`命令、设置组件基础镜像和删除不必要的安装库来优化Docker镜像大小,以提高效率。
摘要由CSDN通过智能技术生成


1 查看镜像id


即执行如下命令:
[root@node-1 ~]# docker images|grep xxx
docker.io/xxx                 1.0              5d1b456495fc        20 hours ago        1.64 GB

注意:
请将xxx替换为你需要查找的镜像名称

2 查看该镜像的分层情况


即执行如下命令:
docker history <image_id>

解释:
docker history是查看镜像的创建历史,最下面是分层的最底层。

[root@node-1 ~]# docker history 5d1b456495fc
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
5d1b456495fc        20 hours ago        /bin/sh -c #(nop)  USER yyy                 0 B                 
<missing>           20 hours ago        /bin/sh -c #(nop)  LABEL maintainer=xxx...   0 B                 
<missing>           20 hours ago        /bin/sh -c #(nop)  LABEL last-commit-id=08...   0 B                 
<missing>           20 hours ago        /bin/sh -c chmod 750 /etc/sudoers.d     &&...   535 B               
<missing>           20 hours ago        /bin/sh -c pip install tenacity===3.1.0   ...   186 MB              
<missing>           20 hours ago        /bin/sh -c #(nop) COPY file:f483b3f3d6368f...   117 B               
<missing>           20 hours ago        /bin/sh -c #(nop) COPY file:a82f5a713f9ec5...   418 B               
<missing>           20 hours ago        /bin/sh -c mkdir /gnocchi-base-source && c...   370 MB              
<missing>           20 hours ago        /bin/sh -c mkdir -p /var/www/cgi-bin/gnocc...   21.2 kB             
<missing>           20 hours ago        /bin/sh -c yum -y install httpd mod_ssl mo...   27 MB               
<missing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值