Created
March 4, 2017 08:54
-
-
Save JanKoppe/777bbd484be5ba5cfc9ff8a35e0c902c to your computer and use it in GitHub Desktop.
Naming Docker Swarm Services after their respective node name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/docker/docker/issues/30966 | |
mostolog commented 19 days ago | |
As you said, swarm nodes get host's hostname as swarm node name (internally). That's perfectly correct for me. | |
After deploying some services with default setting, ps shows something like: | |
37bbf2b56dbf serviceBar.1.ngneetjtxwhm2eijfs1gvt60t | |
a90e2d59cd77 serviceBar.2.d4lf8h3gqj9e7gyhfi3lgrtdt | |
ed6d150d7c84 serviceBar.3.iz85bp0sc5t6e3b15w6gtteus | |
8d7343dfea35 serviceFoo.1.xe9i3vzatpntmmpft0cjup2wa | |
16a283d6e54e serviceFoo.2.4ofjgosnl44p63rkyrlhe7ut0 | |
89f5d450c578 serviceFoo.3.vn1c62qcmagv4m4u9gzgcdj1k | |
5783bbdbf238 serviceEtc.1.xe9i3vzatpnt2eijfs1gvt60t | |
... | |
I don't like that ugly digest...but I could deal with it. | |
Ok...those containers have ugly names, and if I connect to them on different terminals I wouldn't know where am I. So I decided to use --hostname flag. | |
--hostname: {{.Service.Name}}-{{.Task.Slot}} | |
That's ok, but I would love to know in which node is that container running, so | |
--hostname: {{.Service.Name}}-{{.Task.Slot}}-{{.Node.Name}} | |
and ps would display: | |
serviceBar-1-node1 serviceBar.1 | |
serviceBar-2-node3 serviceBar.2 | |
serviceBar-3-node1 serviceBar.3 | |
serviceFoo-1-node2 serviceFoo.1 | |
serviceFoo-2-node3 serviceFoo.2 | |
serviceFoo-3-node1 serviceFoo.3 | |
serviceEtc-1-node2 serviceEtc.1 | |
... | |
and connecting to that container would have set $PS1 and hostname to it (eg:serviceFoo-3-node1) | |
To sum up: now I know where each container is running and where am I if connected to any container | |
:) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment