
【下面的配置过程,在CentOS 7 上验证通过】
On some Linux distributions, such as RHEL and CentOS, the hosts key in the /etc/docker/daemon.json file is overridden by the contents of the docker.service service configuration file. In this case, you need to edit this file manually.
在一些Linux 系统中,如Redhat和CentOS,在/etc/docker/daemon.json 文件中的hosts key 被 docker.service 服务配置文件覆盖了。在这种情况下,我们需要手动编辑该文件。
Use the command sudo systemctl edit docker.service to open the docker.service file in a text editor.
使用 sudo systemctl 编辑 docker.service 文件,在文本编辑器中打开 docker.service 文件。
所在目录:/lib/systemd/system
Add or modify the following lines, substituting your own values.
增加或者修改如下行,如下所示:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
需要注意: -H fd:// 无法启动docker,出现的异常是:no sockets found via socket activation: make sure the service was started by systemd。后来,调整为:-H unix:///var/run/docker.sock,顺利启动 docker service。
然后保存文件。
Reload the systemctl configuration.
重新加载 systemctl 配置。
$ sudo systemctl daemon-reload
Restart Docker.
重启 Docker 服务。
$ sudo systemctl restart docker.service
Check again to see if the dockerd command now listens on both the file descriptor and the network address.
$ sudo ps aux |grep dockerd
[root@local system]# ps aux | grep dockerd
root 26983 0.9 2.9 782448 112816 ? Ssl 16:35 0:01 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
root 27387 0.0 0.0 112720 984 pts/0 S+ 16:38 0:00 grep --color=auto dockerd

现在,Docker Remote API 已经开启好了,可以访问 Docker Remote API,查看返回结果。如下所示,需要修改 IP 地址为 docker server 的IP,其中 端口号为 2375,之前的docker.service配置文件中配置的。
http://192.168.56.101:2375/info
http://192.168.56.101:2375/images/json
http://192.168.56.101:2375/containers/json