简体   繁体   English

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

[英]Docker-swarm >> Cannot connect to the docker engine endpoint

docker version 1.9.1
swarm version 1.0.1

why on connecting 3 VMs (bridged net) to swarm. 为什么要将3个VM(桥接网)连接到swarm。 "docker info" shows me all nodes “docker info”显示了所有节点

Status pending. 状态待定。

1 of 3 hosts is manager all output is from this host. 3个主机中的1个是管理器,所有输出都来自该主机。 I don't know where to look for. 我不知道在哪里寻找。

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

output >> 输出>>

*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

Then 然后

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

Then 然后

root@ubuntu:~# swarm list token://xxxxxxxxxxx

10.32.1.4:2375
10.32.1.33:2375
10.32.1.38:2375

Then 然后

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

heartbeat sorted - runs in background, checked ports, name resolution, pingable from manager. 心跳排序 - 在后台运行,检查端口,名称解析,从管理器pingable。

The docker daemon can listen on three different types of Socket: unix , tcp and fd . docker守护程序可以侦听三种不同类型的Socket: unixtcpfd

By default, docker daemon just listen on unix socket. 默认情况下, docker守护程序只是侦听unix套接字。

If you need to access the Docker daemon remotely, you need to enable the tcp socket. 如果需要远程访问Docker守护程序,则需要启用tcp套接字。

When creating docker swarm cluster, the swarm manager need to access the docker daemon of swarm agent nodes remotely. 在创建docker swarm集群时,swarm管理器需要远程访问swarm代理节点的docker守护程序。

Therefore, you need to re-configure the docker daemon 因此,您需要重新配置docker守护程序

vim /etc/default/docker

Add following line: 添加以下行:

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

Restart docker daemon 重启docker守护进程

sudo restart docker

By doing this, the docker daemon can be accessed remotely. 通过这样做,可以远程访问docker守护程序

References: 参考文献:

  1. Docker document: docker daemon Docker文档:docker守护程序
  2. Docker document: create a swarm for development Docker文档:创建一个用于开发的swarm

I have added DOCKER_OPTS values in /etc/default/docker 我在/ etc / default / docker中添加了DOCKER_OPTS值

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

to be more precise << Host IP >> is same host IP you editing your /etc/default/docker file. 更精确的是“主机IP”是您编辑/ etc / default / docker文件的主机IP。

Maybe it will help someone. 也许它会帮助别人。

Configuration methods differ depending on the host OS on which you're running Docker. 配置方法因运行Docker的主机操作系统而异。

See Docker Daemon configuration instructions (scroll down to find your host OS) : 请参阅Docker守护程序配置说明(向下滚动以查找主机操作系统)
Docker Configuration Documentation Docker配置文档

I'm running Red Hat Enterprise Linux 7.2 : therefore I followed config instructions for my OS form the link above and did the following: 我正在运行Red Hat Enterprise Linux 7.2 :因此我按照上面的链接执行了操作系统的配置说明并执行了以下操作:

  1. mkdir /etc/systemd/system/docker.service.d
  2. Create a docker.conf file 创建docker.conf文件
    vi /etc/systemd/system/docker.service.d/docker.conf
  3. Add the following to the docker.conf file then save. 将以下内容添加到docker.conf文件中,然后保存。

     [Service] ExecStart= ExecStart=/usr/bin/docker daemon -D -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 
  4. Flush Changes 同花顺变化

     systemctl daemon-reload 
  5. Restart Docker 重启Docker

     systemctl restart docker 

The key line of configuration (and where I deviated slightly from the documentation) is: 配置的关键线(以及我稍微偏离文档的地方)是:

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

Let's go through this piece by piece: 让我们一块一块地说明:

  • /usr/bin/docker start from the docker binary /usr/bin/docker从docker二进制文件开始
  • daemon start the Docker Daemon daemon启动Docker守护进程
  • -D start in debug mode (not required) -D以调试模式启动(不需要)
  • -H unix:///var/run/docker.sock creates the default Docker Socket -H unix:///var/run/docker.sock创建默认的Docker Socket
  • -H tcp://0.0.0.0:2375 creates a tcp Docker Socket listening on port 2375 on all network interfaces -H tcp://0.0.0.0:2375 2375在所有网络接口上创建一个侦听端口2375的tcp Docker Socket

After making these changes, I restarted my docker swarm containers (and in my case my Consul containers as well) and ran docker -H tcp://<IP_OF_SWARM_MASTER>:<PORT_YOU_TOLD_SWARM_MASTER_TO_LISTEN_ON> info to see if I was no longer getting the Cannot connect to the docker engine endpoint error. 进行这些更改后,我重新启动了docker swarm容器(在我的情况下也是我的Consul容器)并运行docker -H tcp://<IP_OF_SWARM_MASTER>:<PORT_YOU_TOLD_SWARM_MASTER_TO_LISTEN_ON> info以查看我是否不再获取Cannot connect to the docker engine endpoint错误。

Worked for me by adding in swarm workers service config /usr/lib/systemd/system/docker.service where ExecStart is located this line: 通过添加swarm worker服务配置/usr/lib/systemd/system/docker.service为我工作,其中ExecStart位于以下行:

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

Flush changes and restart Docker: 刷新更改并重新启动Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker.service

But this approach is unprotected, need additional security configs. 但这种方法是不受保护的,需要额外的安全配置。

I tired the solutions mentioned in this thread. 我厌倦了这个帖子中提到的解决方案。 Editing /etc/default/docker did not work for me. 编辑/ etc / default / docker对我不起作用。

Finally what was the following solution. 最后是什么是以下解决方案。

Edit /lib/systemd/system/docker.service file Find the line which starts with ExecStart and add -H=tcp://0.0.0.0:2375 to make it look like 编辑/lib/systemd/system/docker.service文件找到以ExecStart开头并添加-H = tcp://0.0.0.0:2375的行,使其看起来像

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

Save the Modified File Reload the docker daemon 保存修改的文件重新加载docker守护程序

systemctl daemon-reload

Restart the container 重启容器

sudo service docker restart

Test if it is working by using following command 使用以下命令测试它是否正常工作

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

If everything is fine below command should return a JSON. 如果一切正常,则命令应返回JSON。

To test remotely, use the PC name or IP address of Docker Host. 要远程测试,请使用Docker Host的PC名称或IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM