问题现象

docker启动报错,使用systemctl status docker 查看docker状态,显示如下

[root@10-80-119-18 ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Fri 2020-07-10 18:05:49 CST; 5min ago
     Docs: https://docs.docker.com
  Process: 57292 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
 Main PID: 57292 (code=exited, status=1/FAILURE)

Jul 10 18:05:47 10-80-119-19.weinan.7x34.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jul 10 18:05:47 10-80-119-19.weinan.7x34.com systemd[1]: Failed to start Docker Application Container Engine.
Jul 10 18:05:47 10-80-119-19.weinan.7x34.com systemd[1]: Unit docker.service entered failed state.
Jul 10 18:05:47 10-80-119-19.weinan.7x34.com systemd[1]: docker.service failed.
Jul 10 18:05:49 10-80-119-19.weinan.7x34.com systemd[1]: docker.service holdoff time over, scheduling restart.
Jul 10 18:05:49 10-80-119-19.weinan.7x34.com systemd[1]: start request repeated too quickly for docker.service
Jul 10 18:05:49 10-80-119-19.weinan.7x34.com systemd[1]: Failed to start Docker Application Container Engine.
Jul 10 18:05:49 10-80-119-19.weinan.7x34.com systemd[1]: Unit docker.service entered failed state.
Jul 10 18:05:49 10-80-119-19.weinan.7x34.com systemd[1]: docker.service failed.

使用dockerd命令直接启动,输出如下

[root@10-80-119-18 ~]# dockerd
INFO[2020-07-10T17:12:39.818717601+08:00] Starting up                                  
INFO[2020-07-10T17:12:39.821536756+08:00] parsed scheme: "unix"                         module=grpc
INFO[2020-07-10T17:12:39.821589117+08:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-07-10T17:12:39.821628131+08:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-07-10T17:12:39.821647015+08:00] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2020-07-10T17:12:39.823666069+08:00] parsed scheme: "unix"                         module=grpc
INFO[2020-07-10T17:12:39.823713672+08:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-07-10T17:12:39.823743133+08:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-07-10T17:12:39.823758824+08:00] ClientConn switching balancer to "pick_first"  module=grpc
failed to start daemon: error initializing graphdriver: overlay2: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior. Reformat the filesystem with ftype=1 to enable d_type support. Backing filesystems without d_type support are not supported.

问题分析

出现问题的docker配置存储驱动为overlay2,从报错上看,overlay2需要文件系统支持d_type,但出现问题的机器上配置的data-root目录采用的是xfs文件系统,默认并没有开启d_type,需要开启d_type的支持。

什么是d_type

d_type 是 Linux 内核的一个术语,表示 “目录条目类型”,而目录条目,其实是文件系统上目录信息的一个数据结构。d_type,就是这个数据结构的一个字段,这个字段用来表示文件的类型,是文件,还是管道,还是目录还是套接字等。

d_type 从 Linux 2.6 内核开始就已经支持了,只不过虽然 Linux 内核虽然支持,但有些文件系统实现了 d_type,而有些,没有实现,有些是选择性的实现,也就是需要用户自己用额外的参数来决定是否开启d_type的支持。

检查xfs文件系统是否支持d_type

[root@10-80-119-18 ~]# xfs_info /
meta-data=/dev/vda2              isize=256    agcount=9, agsize=2589248 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=20843184, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=5057, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

注意以上输出中的ftype字段,为0则表示不支持。

解决方案

  1. 指定docker的存储驱动类型为devicemapper,devicemapper不需要文件系统支持d_type,但docker官方目前推荐使用overlay2,因此不选择此方案。
  2. 重新格式化docker data-root目录所在的文件系统,xfs格式化时添加参数ftype=1,如下

    mkfs.xfs -n ftype=1 /dev/mapper/vg_data-lv_data -f

    这里采用第二种解决方案

重新启动docker,问题解决

最后修改:2020 年 07 月 14 日
如果觉得我的文章对你有用,请随意赞赏