8

Currently all my nodes have the name ubuntu-yakkety.

docker node ls

ID                           HOSTNAME        STATUS  AVAILABILITY  MANAGER STATUS
d7rdq4n4dmrkhyz4ov7ldr31e    ubuntu-yakkety  Ready   Active        
iddxyuic586lnla6aw700rdwc    ubuntu-yakkety  Ready   Active        
zxcr1yvveccj4soyh2hsjjebk *  ubuntu-yakkety  Ready   Active        Leader

In order to create better filters that would be great if I could update node's hostname as node-01 node-02 ... node-99

However, I couldn't find any way to accomplish it in the documentation.

1) Is it possible to update the hostname of an existing Docker node?

2) Is it possible giving a name to a node while joining to swarm?

Matheus Gontijo
  • 1,178
  • 1
  • 12
  • 29

3 Answers3

6
  1. change hostname: hostname *** or vi /etc/hosts

  2. restart docker: sudo systemctl restart docker

You can see 'Name' user docker info

xiaorun
  • 126
  • 5
  • Sorry but, I have changed my /etc/hosts and restarted but it doesn't changed anything so far... any other thing to do? – Matheus Gontijo Mar 22 '17 at 17:10
  • after doing so, it seems docker node cannot detect the new hostName, `Error response from daemon: rpc error: code = 2 desc = The swarm does not have a leader. It's possible that too few managers are online. Make sure more than half of the managers are online.` – 刘宇翔 Sep 14 '17 at 04:09
  • I left the swarm, edited the hosts file, restarted docker and re-joined the swarm. No change. – CodeOrElse May 31 '18 at 15:08
6

This trio works well:

echo '127.0.0.1 <hostname>' | sudo tee -a /etc/hosts
sudo hostnamectl set-hostname <hostname>
sudo systemctl restart docker
anand
  • 695
  • 9
  • 21
0

You will have to login each nodes and set the node hostname use command:

sudo hostnamectl set-hostname <hostname>

Once you changed all nodes hostname, go the the manager node and restart your docker, after that you should be good.

barbsan
  • 3,418
  • 11
  • 21
  • 28
ericW
  • 31
  • 3