在 CentOS7 上使用 Docker 并启用 aufs

在CentOS7上运行docker时,会将devicemapper用作存储驱动程序,这里记录如何启用aufs。

以下是中国本土化的译文:

– 建议
– 参照
– 引用
– 标准
– 来源
– 指南
– 指示
– 指南方针
– 参考资料
– 参考指南
– 参考书籍
– 参考指引
– 参考文献
– 范例
– 模范
– 示范
-榜样

aufs-backed docker host on centos6 – blog.hansode.org CentOS6の方はこちら
CentOS7(RHEL7) デフォルトで起動するkernelを変更するには
https://github.com/bnied/rhel-aufs-kernel

顺便说一下,为什么要做这样的事情呢,原因是使用无人机 (drone) 在 docker 的存储驱动上使用 devicemapper(默认选项)会导致构建启动时间过长的问题,因此建议切换到 aufs。实际上,切换后立即能够启动。详情请查看链接:https://github.com/drone/drone/issues/271。

安装适用于aufs的内核

请安装在 https://github.com/bnied/rhel-aufs-kernel 提供的aufs兼容内核。

rpm -Uvh https://yum.spaceduck.org/rhel-aufs-kernel/7/x86_64/kernel-ml-aufs-3.19.8-1.el7.centos.x86_64.rpm

选择要启动的内核

因为 CentOS7 使用 grub2,所以可以使用 grub2-set-default 命令进行设置。

$ grep ^menuentry /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.19.8-1.el7.centos.x86_64) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.5-3.el6.x86_64-advanced-aa16c27c-9b7f-4d02-a899-f1fe4dc7cd77' {
menuentry 'CentOS Linux (3.19.8-1.el7.centos.x86_64) 7 (Core) with debugging' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.5-3.el6.x86_64-advanced-aa16c27c-9b7f-4d02-a899-f1fe4dc7cd77' {
menuentry 'CentOS Linux 7 (Core), with Linux 3.10.0-229.el7.x86_64' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.el7.x86_64-advanced-aa16c27c-9b7f-4d02-a899-f1fe4dc7cd77' {
menuentry 'CentOS Linux 7 (Core), with Linux 0-rescue-4627da230679477086e4995bae995b57' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-4627da230679477086e4995bae995b57-advanced-aa16c27c-9b7f-4d02-a899-f1fe4dc7cd77' {

因为 kernel-ml-aufs 似乎是最新的版本,所以选择使用它来启动。

grub2-set-default 'CentOS Linux (3.19.8-1.el7.centos.x86_64) 7 (Core)'
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.orig
grub2-mkconfig -o /boot/grub2/grub.cfg

重新启动

reboot

请确认内核版本已选择为所选项。

$ uname -a
Linux xxxxxxx 3.19.8-1.el7.centos.x86_64 #1 SMP Mon May 25 22:45:44 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

Docker的配置

/etc/sysconfig/docker可以进行改写为,/etc/sysconfig/docker可以进行修改。

other_args="-s aufs"

重新启动

systemctl restart docker

确认是否开启了 aufs。

# docker info
Containers: 0
Images: 0
Storage Driver: aufs
bannerAds