问题
For some background on my environment:
I have docker swarm running on 3 ubuntu 14.04 vagrant boxes. The swarm master is running on 1 machine (with consul) and the other 2 machines are running swarm workers that are joined to the master. I set up the environment following the documentation page https://docs.docker.com/swarm/install-manual/. It is working correctly so that any docker -H :4000 <some_docker_command>
run from my master machine works fine. Service discovery is active as I am running the gliderlabs/registrator container on both of my workers. Any changes to my cluster, such as a node or container failure, are shown by swarm within about 30 seconds (which is a bit slow in my opinion, but at least its working).
The issue:
Swarm recognizes both of my nodes as "ubuntu-14"
vagrant@ubuntu-14:~$ docker -H :4000 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a6972155d243 cohenaj194/apache-simple "/usr/sbin/apache2ctl" About an hour ago Up 13 seconds 172.28.128.6:32770->80/tcp ubuntu-14/test2
af78a8c788ed gliderlabs/registrator "/bin/registrator con" 2 hours ago Up About an hour ubuntu-14/registrator2
8e39416a785a gliderlabs/registrator "/bin/registrator con" 2 hours ago Up 2 hours ubuntu-14/registrator1
27c2225b32fb cohenaj194/apache-simple "/usr/sbin/apache2ctl" 2 hours ago Up 2 hours 172.28.128.4:32770->80/tcp ubuntu-14/test1
vagrant@ubuntu-14:~$ docker -H :4000 network ls
NETWORK ID NAME DRIVER
38b24dc5615b ubuntu-14/bridge bridge
c4e1ffae2fa7 ubuntu-14/bridge bridge
29cf499e57ab ubuntu-14/host host
7b4a4a153ada ubuntu-14/host host
723b6bc6f23c ubuntu-14/none null
01f3647d62cd ubuntu-14/none null
I would like to know how to manually change the name of my nodes from "ubuntu-14" to something else. I would prefer to be able to set the tags by adding a line to the /etc/default/docker
file, as the private cloud I will eventually be running my cluster within does not have a way to set instance tags similar to other cloud providers such as AWS.
tldr: I have 3 vagrant ubuntu boxes running swarm (1 master + 2 workers). The workers by default have the tag name "ubuntu-14" and I want to manually change that by adding something to the /etc/default/docker
file on each worker. What do I add?
回答1:
The solution
## change the hostname
hostname myname
## restart docker
sudo service docker restart
I just changed the hostnames of my vagrant boxes by editing the /etc/hostname
file and changing ubuntu-14 to master, worker1 or worker2. Then I restarted my machines and also had to restart the docker services on each machine with sudo service docker restart
. I also destroyed my old containers and ran them again I'm not sure if this step is necessary, but I did it for good measure.
来源:https://stackoverflow.com/questions/37535185/docker-swarm-how-to-manually-set-node-names