可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
docker version 1.9.1
swarm version 1.0.1
why on connecting 3 VMs (bridged net) to swarm. "docker info" shows me all nodes
Status pending.
1 of 3 hosts is manager all output is from this host. I don't know where to look for.
On running 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.
回答1:
The docker daemon can listen on three different types of Socket: unix, tcp and fd.
By default, docker daemon just listen on unix socket.
If you need to access the Docker daemon remotely, you need to enable the tcp socket.
When creating docker swarm cluster, the swarm manager need to access the docker daemon of swarm agent nodes remotely.
Therefore, you need to re-configure the docker daemon
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
sudo restart docker
By doing this, the docker daemon can be accessed remotely.
References:
- Docker document: docker daemon
- Docker document: create a swarm for development
回答2:
I have added DOCKER_OPTS values in /etc/default/docker
DOCKER_OPTS="-H <>host 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.
Maybe it will help someone.
回答3:
Configuration methods differ depending on the host OS on which you're running Docker.
See Docker Daemon configuration instructions (scroll down to find your host OS):
Docker Configuration Documentation
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:
mkdir /etc/systemd/system/docker.service.d
- Create a docker.conf file
vi /etc/systemd/system/docker.service.d/docker.conf
Add the following to the docker.conf file then save.
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -D -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
Flush Changes
systemctl daemon-reload
Restart 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
daemon
start the Docker Daemon
-D
start in debug mode (not required)
-H unix:///var/run/docker.sock
creates the default Docker Socket
-H tcp://0.0.0.0:2375
creates a tcp Docker Socket listening on port 2375 on all network interfaces
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.
回答4:
Worked for me by adding in swarm workers service config /usr/lib/systemd/system/docker.service
where ExecStart
is located this line:
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
Flush changes and restart Docker:
sudo systemctl daemon-reload
sudo systemctl restart docker.service
But this approach is unprotected, need additional security configs.
回答5:
I tired the solutions mentioned in this thread. Editing /etc/default/docker did not work for me.
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
ExecStart=/usr/bin/docker daemon -H=fd:// -H=tcp://0.0.0.0:2375
Save the Modified File
Reload the docker daemon
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.
To test remotely, use the PC name or IP address of Docker Host.