方法一 修改 docker.service
修改systemctl docker service 文件,加入-H tcp://0.0.0.0:2375
# vi /usr/lib/systemd/system/docker.service
在service 中修改ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 修改为 ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
Before:
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
After:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
修改完成后重启
# systemctl daemon-reload
# systemctl restart docker
方法二 修改daemon.json文件
修改daemon.json文件 添加"hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
{
"hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
}
直接添加后无法启动,查看journal
journalctl -u docker.service -b
报错信息
Oct 31 00:29:54 alma94 systemd[1]: Starting Docker Application Container Engine…
Oct 31 00:29:54 alma94 dockerd[1195406]:** 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: [unix:///var/run/docker.sock tcp://127.0.0.1:2375])**
Oct 31 00:29:54 alma94 systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Oct 31 00:29:54 alma94 systemd[1]: docker.service: Failed with result ‘exit-code’.
Oct 31 00:29:54 alma94 systemd[1]: Failed to start Docker Application Container Engine.
原因是/usr/lib/systemd/system/docker.service 文件中定义了-H fd:// 重复定义 host, 删除。
Before:
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
After:
[Service]
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock
修改完成后重启
# systemctl daemon-reload
# systemctl restart docker
![]()