Search code examples
dockerdocker-swarm

Display FQDN instead of hostname in `docker node ls` output


When I run docker node ls command on swarm cluster the result looks as follows

ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
0yy1e9u4gl7hipgvltffxv0pn *   host1               Ready               Active              Leader              18.09.5
413mv8n6rd9j2nt48km16mta6     host1               Ready               Active                                  18.09.5

The problem is that both servers have the same hostname but differs in the domain name. Is there a way to make swarm use FQDN instead of hostname for node identification? I assumed that it isn't possible but then I stumbled upon this tutorial where the command's output appears to be exactly what I'm looking for. Do you know how I can achieve that?


Solution

  • This depends on what the nodes hostname's are set too.

    By default docker node ls displays the short hostname (e.g. hostname) rather than the FQDN (e.g. hostname -f). You can set the short hostname to the value of the FQDN i.e.: sudo hostname $(hostname -f) (note: this is effective only until the next reboot - man hostname for additional details) and update /etc/hostname i.e: hostname -f |sudo tee /etc/hostname then docker node ls: manager node fqdn

    Wash, rinse and repeat for all your nodes and you should be good: all nodes fqdn

    Update: using swarmkit you can set arbitrary hostname's when joining the swarm cluster: swarmkit node

    It's not possible to set the hostname when joining the swarm using docker swarm join.