[实践OK]CentOS下的Docker DeviceMapper占用空间太大解决方案 不指定

jackxiang 2018-12-5 18:24 | |
/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

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/9978/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2018-12-6 10:46
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]