Docker守护进程连接到2375上的套接字

我已经configuration了我的Docker版本1.12的systemd来侦听端口:2375。

[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target [Service] Type=notify ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 ExecReload=/bin/kill -s HUP MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process [Install] WantedBy=multi-user.target 

结果是:

 *tcp6 0 0 :::2375 :::* LISTEN* 

但是,当我尝试在主机的terminal上使用“docker”命令时,我正在运行Docker,得到以下结果:

  [root@docker1-12 ~]# docker images Cannot connect to the Docker daemon. Is the docker daemon running on this host? Even though the docker.service is actually running: ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2016-12-30 14:50:53 AEDT; 1min 32s ago Docs: https://docs.docker.com Main PID: 4976 (dockerd) Memory: 21.1M CGroup: /system.slice/docker.service ├─4976 /usr/bin/dockerd -H tcp://0.0.0.0:2375 └─4982 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime do... Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.083736426+11:00" level=info msg="[graphdriver] using prior storage driver \"devicemapper\"" Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.091254467+11:00" level=info msg="Graph migration to content-addressability took 0.00 seconds" Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.095445562+11:00" level=info msg="Loading containers: start." Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.128643621+11:00" level=info msg="Firewalld running: true" Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.919797126+11:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address" Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.274835533+11:00" level=info msg="Loading containers: done." Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.275468481+11:00" level=info msg="Daemon has completed initialization" Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.275501250+11:00" level=info msg="Docker daemon" commit=7392c3b graphdriver=devicemapper version=1.12.5 Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.285288956+11:00" level=info msg="API listen on [::]:2375" Dec 30 14:50:53 docker1-12 systemd[1]: Started Docker Application Container Engine. 

我怎样才能解决这个问题? 即让docker监听端口:2375,同时能够在主机上本地运行docker命令?

注意我find了以下configuration,作为解决方法。 但是,这似乎并不适用于Docker版本1.12:

 Environment="DOCKER_OPTS=-H tcp://0.0.0.0:2375 --exec-opt native.cgroupdriver=cgroupfs" ExecStart=/usr/bin/docker daemon -H fd:// \$DOCKER_OPTS 

我可以想到2个选项:

1.更改您的systemd单元文件:

 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock 

这样,你将在tcp上监听networkingAPI调用,并在本地docker cliunix sock上监听。

2.当使用docker cli尝试连接时,请使用以下命令:

 export DOCKER_HOST="tcp://0.0.0.0:2375" docker ps 

同样的效果一个class轮:

 sudo docker -H tcp://0.0.0.0:2375 ps