Docker服务出现异常后,无法正常启动

347 阅读2分钟

//查看启动配置 /lib/systemd/system/docker.service

...

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# 通过这里启动文件我们发现docker启动的时候是调用了这个2进制文件/usr/bin/dockerd
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
...

查看/usr/bin/dockerd

[root@VM-20-17-centos system]# ls -al /usr/bin/dockerd
---------- 1 root root 96792616 Dec 13 19:45 /usr/bin/dockerd
# 说明我们在某个条件时出现了问题导致这个文件现在没有了执行权限,这里权限本应该是751的格式
# 但是我们通过root用户去chmod 755 /usr/bin/dockerd 是不行的,我们要先处理以下这个文件

[root@VM-20-17-centos system]# lsattr /usr/bin/dockerd
----i--------e-- /usr/bin/dockerd
[root@VM-20-17-centos system]# sudo chattr -i libprotobuf.so # 注意chattr修改文件属性需要root权限
[root@VM-20-17-centos system]# lsattr /usr/bin/dockerd
-------------e-- /usr/bin/dockerd
[root@VM-20-17-centos system]# chmod 751 /usr/bin/dockerd
-rwxr-x--x 1 root root 96792616 Dec 13 19:45 /usr/bin/dockerd

# 查看docker目录下的内容
[root@VM-20-17-centos system]#cd /var/lib/docker
buildkit  containerd  containers  image  network  overlay2  plugins  runtimes  swarm  tmp  trust  volumes
# 注意这里的overlay2,你下载的image内容即文件一层一层就是放在overlay2里面的,iamge下有个overlay2,你启动的container就是放到containers下的,容器与宿主机匿名映射路径和具名映射路径就是vloumes下,网络在network下

# 刚才我们提到过的/lib/systemd/system/docker.service文件
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 这个选项不是每个人都这样写的,为了关联上overlay2这里可以人工改一下
# ExecStart=/usr/bin/dockerd -H fd:// -s overlay
# 如果启动的时候没有找到你之前安装的内容,可以先改成
# ExecStart=/usr/bin/dockerd -H fd:// -s overlay2
# 如果启动阻塞了,你退出来在改后来ExecStart=/usr/bin/dockerd -H fd:// -s overlay,然后再启动
# 这里我也是没弄明白,反复试了几次,最后还是关联上了之前已经配置好的容器,但是原理就是这里