Docker服务启动报错的解决方法

1.报错起因

修改了Docker /etc/docker/daemon.json配置文件,内容配置如下(增加了hosts配置,用于开启远程Docker API):

{
     "registry-mirrors":["https://b9pmyelo.mirror.aliyuncs.com"],
     "hosts":["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]
}

2. 重启Docker服务报错

# systemctl restart docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

3.问题排查

查看服务状态

# 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 四 2021-07-29 10:20:32 CST; 8s ago
     Docs: https://docs.docker.com
  Process: 2656 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
 Main PID: 2656 (code=exited, status=1/FAILURE)

手动启动docker

# /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: hosts: (from flag: [fd://], from file: [tcp://0.0.0.0:2375 unix:///var/run/docker.sock])

发现错误信息,说的已经很明确了,/etc/docker/daemon.json文件导致了docker守护进程无法启动!
也就说启动守护进程的命令/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock-H指定了hosts配置,daemon.json配置文件也配置了hosts,两者有冲突!

4.解决方法

两种解决方法:
1. 修改/usr/lib/systemd/system/docker.service文件
修改/usr/lib/systemd/system/docker.service文件去掉-H fd://
Docker服务启动报错的解决方法_第1张图片
然后将fd://添加到daemon.jsonhosts节点中:
Docker服务启动报错的解决方法_第2张图片

然后重启docker服务

systemctl daemon-reload
systemctl restart docker.service

OK!
如果你必须要tcp://0.0.0.0:2375的host配置,那只能使用这种方式解决!如果这个是不必要的可以使用下面的解决方法2。

2. 去掉daemon.jsonhosts配置

{
     "registry-mirrors":["https://b9pmyelo.mirror.aliyuncs.com"] 
}

然后重启docker服务

systemctl daemon-reload
systemctl restart docker.service

你可能感兴趣的:(Docker)