Node ID / Host Name:
| A docker node |
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
s5id2jv8uofjfmbbiqiqe6nnx * ubuntu Ready Active Leader
Note that the above-mentioned ID is the node id.
Each host that participates in a docker swarm is called a node. A node (a host) has a NODE ID (a swarm given identity) and a hostname (an independent name that has always been there with the host even before joining a swarm). I have highlighted the NODE ID (the swarm thing) and the hostname in the above image.
Service ID / Service Name:
| Creating a single replica of a service |
When we create a service - we are actually creating a running instance from the image that we call a task (a container) in swarm mode. Since we are creating just one replica here, we are creating just one task.
$ docker service create --name django httpd
Now we want to check the the service(s) running on this swarm -
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ep9luuvn21y2 django replicated 1/1 httpd:latest
Note that that above mentioned ID is the service ID
Task ID / Task Name:
$ docker service ps django OR$ docker service ps ep9luuvn21y2
ID NAME IMAGE NODE DESIRED St CURRENT St ERROR PORTS
y2n63eaa1ln3 django.1 httpd:latest ubuntu Running Running 17 minutes ago
When you want to list the tasks of one or more services, use service ps command.
The list of tasks informs task id as well as the task name (servicename.#) and the node name (hostname) is it running on.
| docker node ps OR docker service ps SERVICENAME show information from node (all services) and service (all nodes) perspective |
Note -
$docker service ps SERVICES_NAMES <--- div="" list="" more="" nbsp="" of="" one="" or="" services="" tasks="" the="">--->
From the following commands, also notice that the task name and task id form the underlying container name while container id happens to be something else.
$docker node ps [NODES] <--- i="" nbsp="">List tasks running on one or more nodes, defaults to current node--->
So by now, we are familiar with NODE ID / NODE NAME (hostname), SERVICE ID / SERVICE NAME, TASK ID / TASK NAME and the commands to list them. The commands are 'docker node ls', 'docker service ls', 'docker service ps SERVICE_NAME or SERVICE_ID' OR 'docker node ps NODE_NAME or NODE_ID'.
Let us make it easier to understand through the following image -
Task ID & Task Name Vs. Container ID & Container Name:
From the following commands, also notice that the task name and task id form the underlying container name while container id happens to be something else.
Putting everything together - Using Templates:
Using a template we can pass a customized hostname, mount, or env values to a container at the time of service creation.
Now let us try to understand the Templates through this sequence of commands -
Here first we create a service with --hostname variable set go GO Language styled variable it will set the hostname within the going-to-be created container under this service. In the example here, the hostname recorded within the container is composed of node's hostname, node's id and the service name.
The last command in the sequence is trying to paste that hostname recorded within the container back to screen (re-pasted below) -
docker container inspect --format="{{.Config.Hostname}}" hosttempl.1.xudl0i6soylcnhep47nvog4nn
ubuntu-s5id2jv8uofjfmbbiqiqe6nnx-hosttempl
No comments:
Post a Comment