清洁码头工作环境:devicemapper [英] Clean docker environment: devicemapper

查看:217
本文介绍了清洁码头工作环境:devicemapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有2个容器的码头环境(Jenkins和Nexus,都有自己命名的卷)。
我有一个每日cron-job,它删除未使用的容器和图像。这工作正常但问题出在我的设计版本中:

  du -sh / var / lib / docker / 
30G docker /

我可以在我的docker文件夹中的每个文件夹:
卷(大,但在我的案例):

  / var / lib / docker#du -sh volumes / 
14G卷/

容器:

  / var / lib / docker#du -sh containers / 
3.2M container /

图片:

  / var / lib / docker#du -sh image / 
5.8M image /

Devicemapper:

  / var / lib / docker#du -sh devicemap / / 
16G devicemap / /

code> / var / lib / docker / devicemapper / mnt 是7.3G
/ var / lib / docker / devicemapper / devicemapper 是8.1G



Docker信息:

 存储驱动程序: devicemapper 
池名称:docker-202:1-xxx-pool
池块大小:65.54 kB
基本设备大小:10.74 GB
备份文件系统:ext4
数据文件:/ dev / loop0
元数据文件:/ dev / loop1
数据空间使用:5.377 GB
数据空间总计:107.4 GB
可用数据空间:28.8 GB
使用的元数据空间:6.148 MB
元数据空间总计:2.147 GB
元数据空间可用:2.141 GB
Udev同步支持:true

这个空间是什么清理这个没有打破东西?

解决方案

不要使用devicemapper循环文件进行任何严重的! Docker对此有很大的警告。



/ var / lib / docker / devicemapper / devicemapper 目录包含稀疏循环文件包含docker所挂载的所有数据。所以你需要使用lvm工具来拖曳他们并做些事情。通过移除问题与devicemapper 进行阅读,他们有点解决了,但可能没有。



如果可能,我将从 devicemapper 中移除,或在RHEL上使用LVM瘦池。如果您无法更改存储驱动程序,则相同的过程至少会清除您无法回收的任何已分配的稀疏空间。



更改docker存储驱动程序



更改存储驱动程序将需要转储您的 / var / lib / docker 包含所有码头数据的目录。有一些方法可以节省部分内容,但这需要解决Docker内部问题。更好地提交和导出要保留的任何容器或卷,并在更改后导入。否则你会有一个新鲜的,空的Docker安装!


  1. 导出数据


  2. 停止Docker


  3. 删除 / var / lib / docker


  4. 修改Docker启动以使用新的存储驱动程序。
    /lib/systemd/system/docker.service中设置 - storage-driver =< name> /etc/systemd/system/docker.service / etc / default / docker / etc / sysconfig / docker


  5. 启动Docker


  6. 导入数据




AUFS



AUFS不在主线内核(而永远不会)发行公司必须积极地包括它。对于Ubuntu,它在 linux-image-extra 包中。

  apt -get install linux-image-extra-$(uname -r)linux-image-extra-virtual 

然后将存储驱动程序选项更改为 - storage-driver = aufs



OverlayFS



OverlayFS已经可用Ubuntu,只需将存储驱动程序更改为 - storage-driver = overlay2 - storage-driver = overlay if你还在使用3.x内核



我不知道这是一个好主意。它不能比循环文件差得多,但是
overlay2 驱动程序对于开发人员使用是非常可靠的,但不被视为生产准备就绪(例如Docker Enterprise不提供支持),但是由于AUFS /内核问题,它被推送成为标准驱动程序。



直接LVM瘦池



而不是devicemapper循环文件,您可以直接使用LVM瘦池。 RHEL可以通过 docker-storage-setup 实用程序,其分发与他们的EPEL码头包。 Docker也有详细的手动设置卷的步骤

   -  storage-driver = devicemapper --storage-opt = dm .thinpooldev = / dev / mapper / docker-thinpool --storage-opt dm.use_deferred_removal = true 

永远不要在LVM卷中用尽空间。


I have a docker environment with 2 containers (Jenkins and Nexus, both with their own named volume). I have a daily cron-job which deletes unused containers and images. This is working fine. But the problem is inside my devicemapper:

du -sh /var/lib/docker/
30G docker/

I can each folder in my docker folder: Volumes (big, but that's normal in my case):

/var/lib/docker# du -sh volumes/
14G volumes/

Containers:

/var/lib/docker# du -sh containers/
3.2M    containers/

Images:

/var/lib/docker# du -sh image/
5.8M    image/

Devicemapper:

/var/lib/docker# du -sh devicemapper/
  16G   devicemapper/

/var/lib/docker/devicemapper/mnt is 7.3G /var/lib/docker/devicemapper/devicemapper is 8.1G

Docker info:

Storage Driver: devicemapper
 Pool Name: docker-202:1-xxx-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: ext4
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 5.377 GB
 Data Space Total: 107.4 GB
 Data Space Available: 28.8 GB
 Metadata Space Used: 6.148 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.141 GB
 Udev Sync Supported: true

What is this space and am I able to clean this without breaking stuff?

解决方案

Don't use a devicemapper loop file for anything serious! Docker has big warnings about this.

The /var/lib/docker/devicemapper/devicemapper directory contains the sparse loop files that contain all the data that docker mounts. So you would need to use lvm tools to trawl around them and do things. Have a read though the remove issues with devicemapper, they are kinda sorta resolved but maybe not.

I would move away from devicemapper where possible or use LVM thin pools on RHEL. If you can't change storage drivers, the same procedure will at least clear up any allocated sparse space you can't reclaim.

Changing the docker storage driver

Changing storage driver will require dumping your /var/lib/docker directories which contains all your docker data. There are ways to save portions of it but that involves messing around with Docker internals. Better to commit and export any containers or volumes you want to keep and import them after the change. Otherwise you will have a fresh, blank Docker install!

  1. Export data

  2. Stop Docker

  3. Remove /var/lib/docker

  4. Modify your docker startup to use the new storage driver. Set --storage-driver=<name> in /lib/systemd/system/docker.service or /etc/systemd/system/docker.service or /etc/default/docker or /etc/sysconfig/docker

  5. Start Docker

  6. Import Data

AUFS

AUFS is not in the mainline kernel (and never will be) which means distro's have to actively include it somehow. For Ubuntu it's in the linux-image-extra packages.

apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

Then change the storage driver option to --storage-driver=aufs

OverlayFS

OverlayFS is already available in Ubuntu, just change the storage driver to --storage-driver=overlay2 or --storage-driver=overlay if you are still using a 3.x kernel

I'm not sure how good an idea this is right now. It can't be much worse than the loop file but The overlay2 driver is pretty solid for dev use but isn't considered production ready yet (e.g. Docker Enterprise don't provide support) but it is being pushed to become the standard driver due to the AUFS/Kernel issues.

Direct LVM Thin Pool

Instead of the devicemapper loop file you can use an LVM thin pool directly. RHEL makes this easy with a docker-storage-setup utility that distributed with their EPEL docker package. Docker also have detailed steps for setting up the volumes manually.

--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true

Just don't run out of space in the LVM volume, ever.

这篇关于清洁码头工作环境:devicemapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆