Docker-swarm >>无法连接到docker引擎端点

docker version 1.9.1 swarm version 1.0.1 

为什么连接3个虚拟机(桥接networking)群体。 “docker信息”显示我所有的节点

待处理状态

3个主人中的1个是经理所有的输出都是从这个主机。 我不知道在哪里寻找。

在运行swarm --debug manage token://XXXXX

输出>>

 *INFO[0000] Listening for HTTP addr=127.0.0.1:2375 proto=tcp DEBU[0000] Failed to validate pending node: Cannot connect to the docker engine endpoint Addr=10.32.1.38:2375 DEBU[0000] Failed to validate pending node: Cannot connect to the docker engine endpoint Addr=10.32.1.4:2375 DEBU[0000] Failed to validate pending node: Cannot connect to the docker engine endpoint Addr=10.32.1.33:2375 

然后

 root@ubuntu:~# ps -ef | grep swarm root 2158 1391 0 12:28 pts/2 00:00:00 swarm join token://xxxxxxx --addr 10.32.1.4:2375 root 2407 1213 0 13:57 pts/1 00:00:00 swarm manage token://xxxxxxx -H 0.0.0.0:4243 root 2413 1391 0 13:57 pts/2 00:00:00 grep --color=auto swarm 

然后

 root@ubuntu:~# swarm list token://xxxxxxxxxxx 10.32.1.4:2375 10.32.1.33:2375 10.32.1.38:2375 

然后

 root@ubuntu:~# ps -ef | grep docker root 2330 1 0 12:52 ? 00:00:00 /usr/bin/docker daemon root 2421 1391 0 14:10 pts/2 00:00:00 grep --color=auto docker 

心跳sorting – 在后台运行,检查端口,名称parsing,从pipe理器pingable。

docker守护进程可以侦听三种不同types的Socket: unixtcpfd

默认情况下, docker守护进程只监听unix套接字。

如果您需要远程访问Docker守护程序,则需要启用tcp套接字。

在创builddocker群集时,群集pipe理器需要远程访问群集代理节点的docker守护程序。

因此,您需要重新configurationdocker守护进程

 vim /etc/default/docker 

添加以下行:

 DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock" 

重新启动docker守护进程

 sudo restart docker 

通过这样做, docker守护进程可以远程访问。

参考文献:

  1. Docker文档:docker守护进程
  2. Docker文档:创build一个swarm进行开发

我在/ etc / default / docker中添加了DOCKER_OPTS值

DOCKER_OPTS =“ – H <>主机IP <>:2375 -H unix:///var/run/docker.sock”

更精确的“主机IP”是你编辑你的/ etc / default / docker文件的主机IP。

也许它会帮助别人。

configuration方法取决于您运行Docker的主机操作系统。

请参阅Docker Daemonconfiguration说明(向下滚动以查找您的主机操作系统)
Dockerconfiguration文档

我正在运行红帽企业Linux 7.2 :因此,我遵循我的操作系统的configuration说明从上面的链接,并做了以下几点:

  1. mkdir /etc/systemd/system/docker.service.d
  2. 创build一个docker.conf文件
    vi /etc/systemd/system/docker.service.d/docker.conf
  3. 将以下内容添加到docker.conf文件中,然后保存。

     [Service] ExecStart= ExecStart=/usr/bin/docker daemon -D -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 
  4. 冲洗变化

     systemctl daemon-reload 
  5. 重新启动Docker

     systemctl restart docker 

configuration的关键线(以及我从文档中稍微偏离的地方)是:

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

让我们一块一块地看看:

  • /usr/bin/docker从docker二进制文件开始
  • daemon启动Docker守护进程
  • -D在debugging模式下启动(不需要)
  • -H unix:///var/run/docker.sock创build默认的Docker套接字
  • -H tcp://0.0.0.0:2375 2375在所有networking接口上的端口2375上创build一个tcp Docker Socket侦听

进行这些更改后,我重新启动了我的Docker群集容器(在我的情况下也是我的Consul容器),然后运行docker -H tcp://<IP_OF_SWARM_MASTER>:<PORT_YOU_TOLD_SWARM_MASTER_TO_LISTEN_ON> info以查看我是否不再Cannot connect to the docker engine endpoint错误。

通过在swarm workers中添加service config /usr/lib/systemd/system/docker.service来为我工作,其中ExecStart位于以下行:

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

刷新更改并重新启动Docker:

 sudo systemctl daemon-reload sudo systemctl restart docker.service 

但是这种方法是不受保护的,需要额外的安全configuration。

我厌倦了这个线程中提到的解决scheme。 编辑/ etc / default / docker对我不起作用。

最后是什么下面的解决scheme。

编辑/lib/systemd/system/docker.service文件find以ExecStart开头的行,并添加-H = tcp://0.0.0.0:2375,使其看起来像

 ExecStart=/usr/bin/docker daemon -H=fd:// -H=tcp://0.0.0.0:2375 

保存修改后的文件重新加载docker守护进程

 systemctl daemon-reload 

重新启动容器

 sudo service docker restart 

使用以下命令testing它是否正在工作

 curl http://localhost:2375/images/json 

如果一切正常下面的命令应该返回一个JSON。

要远程testing,请使用Docker主机的PC名称或IP地址。