Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I update the hostname of a Docker Node?

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?

like image 313
Matheus Gontijo Avatar asked Mar 21 '17 02:03

Matheus Gontijo


People also ask

How do I change the hostname of a docker container?

Running the command "sudo nsenter --target 1 --uts hostname <my new hostname>" from inside the container did the trick.

What is docker hostname?

In the same way, a container's hostname defaults to be the container's ID in Docker. You can override the hostname using --hostname . When connecting to an existing network using docker network connect , you can use the --alias flag to specify an additional network alias for the container on that network.

What is the docker command to add or update a node label?

Run docker node update --label-add on a manager node to add label metadata to a node. The --label-add flag supports either a <key> or a <key>=<value> pair. The labels you set for nodes using docker node update apply only to the node entity within the swarm.

How do you change the leader on a docker Swarm?

But, to answer your question, there is no way to manually set the swarm leader. However, what you can do is docker node demote the leader (swarm2), and the other manager (swarm3). Once the managers are demoted to workers, swarm1 by default becomes the leader.


2 Answers

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

  2. restart docker: sudo systemctl restart docker

You can see 'Name' user docker info

like image 139
xiaorun Avatar answered Oct 08 '22 09:10

xiaorun


This trio works well:

echo '127.0.0.1 <hostname>' | sudo tee -a /etc/hosts
sudo hostnamectl set-hostname <hostname>
sudo systemctl restart docker
like image 37
anand Avatar answered Oct 08 '22 10:10

anand