Docker 容器镜像是一个轻量、独立、含有运行某个应用所需全部软件的可执行包,那么一个 Docker 镜像里面会包含什么东西?这个名为 Dive 的工具正是用来分析和浏览 Docker 镜像每层的内容。

通过分析 Docker 镜像,我们可以发现在各个层之间可能重复的文件,并通过移除它们来减小 Docker 镜像的大小。

Dive 是一个用 Go 语言编写的自由开源工具。Dive 工具不仅仅是一个 Docker 镜像分析工具,它还可以帮助使用者用于构建镜像。

RHEL/Centos

curl -OL https://github.com/wagoodman/dive/releases/download/v0.3.0/dive_0.3.0_linux_amd64.rpm
rpm -i dive_0.3.0_linux_amd64.rpm


来自:https://javascript.ctolib.com/wagoodman-dive.html
/var/lib/docker/devicemapper/devicemapper/data
scp /var/lib/docker/devicemapper/devicemapper/data root@10.71.165.136:/var/lib/docker/devicemapper/devicemapper/data  #这个方法不行,看有2G,一拷贝有20G
步骤1)挂载盘:
rm -rf /var/lib/docker/
mkdir -p /var/lib/docker/devicemapper/
mkdir -p  /data/docker/devicemapper/devicemapper    
ln -sf /data/docker/devicemapper/devicemapper /var/lib/docker/devicemapper/devicemapper
ll /var/lib/docker/devicemapper/devicemapper
lrwxrwxrwx 1 root root 38 Dec  5 22:35 /var/lib/docker/devicemapper/devicemapper -> /data/docker/devicemapper/devicemapper

步骤2)卸载重装Docker:
yum remove docker-ce
yum install docker-ce
systemctl start docker
docker images
cd /lib/systemd/system
mv docker.service docker.service.init0
mv docker.service.proxy.ok docker.service
systemctl daemon-reload
systemctl restart docker


步骤3)检查是否给把原来的大的挂载磁盘给软链接进来了:

#du -sh /var/lib/docker/devicemapper/devicemapper/data
11M     /var/lib/docker/devicemapper/devicemapper/data

[root@docker_build_bj_sjs_10_71_159_11:~]
#ls -lart /var/lib/docker/devicemapper/devicemapper
lrwxrwxrwx 1 root root 38 Dec  5 22:35 /var/lib/docker/devicemapper/devicemapper -> /data/docker/devicemapper/devicemapper

附录:docker.service




5.1G    /var/lib/docker/devicemapper/devicemapper/data  #这个可能38G,太大,40G盘存不下来。

都有可能。得按方法二,来处:https://blog.csdn.net/CHENYUFENG1991/article/details/79839497

解决方案2:成功
停止docker!!!这一步很关键,否则下面的设置会失败。
编辑以下文件:
vim /lib/systemd/system/docker.service

原内容如下:
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY\
          $REGISTRIES


然后修改为以下:
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          --storage-opt dm.loopdatasize=8G \
          --storage-opt dm.loopmetadatasize=4G \
          --storage-opt dm.basesize=8G \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY\
          $REGISTRIES


也就是多加以下3行:
          --storage-opt dm.loopdatasize=8G \
          --storage-opt dm.loopmetadatasize=4G \
          --storage-opt dm.basesize=8G \

设置devicemapper的data为8G,metadata为4G,镜像的大小不能大于8G。

删除原有docker,并使用dd命令进行空间分配
rm -rf /var/lib/docker
mkdir -p /var/lib/docker/devicemapper/devicemapper/
dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1M count=0 seek=8192
dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/metadata bs=1M count=0 seek=4096

完成上述步骤后
systemctl daemon-reload
systemctl start docker
docker info

分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]