目录

隐藏
  1. CentOS 7 的内核太老了 3.10,是不是很多 Docker 功能不支持?
  2. 挂载宿主目录,结果 Permission denied,没权限
  3. Docker的 /var/lib/docker/devicemapper 占用空间不断增长, 怎么破?
  4. 在 CentOS 6 上安装后怎么最高只有 Docker 1.7 这个版本?
  5. CentOS 7/RHEL 7 升级 1.12 后,无法启动,怎么回事?
CentOS 7 的内核太老了 3.10,是不是很多 Docker 功能不支持?
是的,有一些功能无法支持,比如 overlay2 的存储驱动就无法在 CentOS 上使用,但并非所有需要高版本内核的功能都不支持。

比如 Overlay FS 需要 Linux 3.18,而 Overlay network 需要 Linux 3.16。而 CentOS 7 内核为 3.10,确实低于这些版本需求。但实际上,红帽团队会把一些新内核的功能 backport 回老的内核。比如 overlay fs等。所以一些功能依旧会支持。因此 CentOS 7 的 Docker Engine 同样可以支持 overlay network,以及 overlay 存储驱动(不是overlay2)。因此在新的 Docker 1.12 中,CentOS/RHEL 7 才有可能支持 Swarm Mode。

即使红帽会把一些高版本内核的功能 backport 回 3.10 内核中,这种修修补补出来的功能,并不一定稳定。如果观察 Docker Issue 列表,会发现大量的由于 CentOS 老内核导致的问题,特别是在使用了 1.12 内置的 Swarm Mode 集群功能后,存储、网络出现的问题很多。

所以依旧建议使用其它维护内核版本升级的 Linux 发行版,如 Ubuntu。

挂载宿主目录,结果 Permission denied,没权限
原因是 CentOS/RHEL中的 SELinux 限制了目录权限。需要添加规则。

下面是 man docker-run 的解释:

When  using  SELinux,  be  aware that the host has no knowledge of container
SELinux policy. Therefore, in the above example, if SELinux policy  is enforced,
the /var/db directory is not  writable to the container. A "Permission Denied"
message will occur and an avc: message in the host's syslog.
To  work  around  this, at time of writing this man page, the following command
needs to be run in order for the  proper  SELinux  policy  type label to be
attached to the host directory:
因此需要对特定目录添加规则

$ chcon -Rt svirt_sandbox_file_t /var/db
参考: http://www.projectatomic.io/blog/2015/06/using-volumes-with-docker-can-cause-problems-with-selinux/

Docker的 /var/lib/docker/devicemapper 占用空间不断增长, 怎么破?
这类问题一般是 CentOS/RHEL 红帽系的问题,CentOS 这类红帽系统中,由于不像 Ubuntu 那样有成熟的 Union FS实现(如aufs),所以只能使用 devicemapper,而默认使用的是lvm-loop,也就是用一个稀疏文件来当成一个块设备,给devicemapper用,作为Docker镜像容器文件系统。这是非常不推荐使用的,性能很差不说,不稳定,还有很多 bug,如果没办法换 Ubuntu/Debian 系统,那么最起码应该建立块设备(分区、卷)给 devicemapper 用。

参考官网文档: https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#configure-direct-lvm-mode-for-production

严格来说 CentOS/RHEL 7 中实际上有一个 Union FS 实现,虽然 CentOS/RHEL 7 的内核是 3.10,不过红帽从 Linux 3.18 backport 回来了 overlay fs 的驱动。但是,红帽自己都在官方的发布声明中说能不要用就不用。

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/7.2_Release_Notes/technology-preview-file_systems.html

在 CentOS 6 上安装后怎么最高只有 Docker 1.7 这个版本?
Docker 已经不再支持 CentOS 6 了,现在看到的是很久以前的老版本,之后再也没有发布过 CentOS 6 的版本。

所以不要再在 CentOS 6上用 Docker 了。换 CentOS 7 或者 Ubuntu 吧。

挂载宿主目录,结果 Permission denied,没权限

原因是 CentOS/RHEL中的 SELinux 限制了目录权限。需要添加规则。

下面是 man docker-run 的解释:

When  using  SELinux,  be  aware that the host has no knowledge of container
SELinux policy. Therefore, in the above example, if SELinux policy  is enforced,
the /var/db directory is not  writable to the container. A "Permission Denied"
message will occur and an avc: message in the host's syslog.
To  work  around  this, at time of writing this man page, the following command
needs to be run in order for the  proper  SELinux  policy  type label to be
attached to the host directory:
因此需要对特定目录添加规则

$ chcon -Rt svirt_sandbox_file_t /var/db
参考: http://www.projectatomic.io/blog/2015/06/using-volumes-with-docker-can-cause-problems-with-selinux/

CentOS 7/RHEL 7 升级 1.12 后,无法启动,怎么回事?
一些人在升级之后,启动 Docker 时发现无法启动,而在报错中看到:

Unit docker.socket failed to load: No such file or directory.
其原因是由于从 1.12 开始,不需要在 systemd 中写个 docker.socket 文件了,所以这个文件就随升级而删除了。而 docker.service 由于被修改过(或别的什么原因),导致 yum 升级的时候没有替换这个文件。于是出现了旧的 docker.service 中配置要求有 docker.socket 文件,而这个文件已经在新的版本中删除了,所以导致启动错误。

解决办法很简单,直接打开 docker.service,将其参照 1.12 的默认配置文件修改即可。寻找到 Required=docker.socket 那行,删掉。然后寻找到 docker daemon(或者 dockerd) 那行,将其后的 -H fd:// 删掉。并且进一步将 docker daemon 改为 dockerd,因为从 1.12 开始改名叫这个了。保存退出重启服务即可。