背景
centos7
场景
在 /etc/docker/daemon.json 添加如下代码:
{
"registry-mirrors": ["https://qgm5dyuu.mirror.aliyuncs.com","https://registry.docker-cn.com"],
"bip": "10.0.0.1/16",
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
}
错误
启动不起来,错误代码
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
[root@localhost ~]# systemctl status docker.service
?.docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2020-11-03 15:09:17 CST; 50s ago
Docs: https://docs.docker.com
Process: 40602 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 40602 (code=exited, status=1/FAILURE)
Nov 03 15:09:15 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: Failed to start Docker Application Container Engine.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Service RestartSec=2s expired, scheduling restart.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: Stopped Docker Application Container Engine.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Start request repeated too quickly.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Failed with result 'exit-code'.
Nov 03 15:09:17 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: Failed to start Docker Application Container Engine.
Nov 03 15:09:18 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Start request repeated too quickly.
Nov 03 15:09:18 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: docker.service: Failed with result 'exit-code'.
Nov 03 15:09:18 iZ8vbi4t4rsi4lb9e7bkckZ systemd[1]: Failed to start Docker Application Container Engine.
原因
docker 的 socket 配置hosts出现了冲突
解决办法
vi /usr/lib/systemd/system/docker.service
将ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
修改为ExecStart=/usr/bin/dockerd
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[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
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
使之生效
systemctl daemon-reload
重新启动docker即可
systemctl start docker