- [Instructor] With Docker Swarm you have the option
to add what they call node labels.
So, your Docker Swarm nodes can be
labeled with whatever tag you choose.
To do this you use the docker node update command
with --label-add,
the name of the label,
and then the name of the node or the node ID.
Let's give it a try over at the command line.
So, that command, again, is docker node update,
and --label-add,
and then whatever label you want to add to this docker node.
So, we could call this prio1 for priority one
and then we put the name of the node after that.
So, in this case, it's DC2-N1.
That's the name of this node.
I'll press Enter.
And what can be confusing here is that,
if you do a docker node ls, you would think
that you would see the name of
the label in the list of nodes here.
Or at least you could filter the nodes that had that label.
But, according to the documentation, that's not possible.
You can see the labels that you create
with the docker node inspect command.
So, we'll do docker node inspect,
and we'll do DC2-N1, and we'll pipe that to more.
And right here, towards the top, you cans see labels prio1.
There's the prio1 label that we added.
So, what else can you do with these labels?
Other than view them with docker inspect,
what's the point of these labels?
Well, you can see the labels over
in the universal control plane,
and there may be some functionality
that you can use there with the labels
once they're applied to the nodes.
Another bit of functionality with labels is
when you go to deploy new services,
you can actually perform what they call service constraints.
So, when we go to create a new service,
for example, in this example here.
You could say that the constraint on this service
is that it can only run on nodes
with labels that have the type queue, in this case.
Or, in our example, we could say that we want
our service to only run on the nodes
that have the label prio1 for priority one.
Docker Swarm node labels give you control
over exactly where your services will run,
specifically which nodes the will run on.
And there's a number of benefits to doing this.
For example, maybe you want a credit card processing service
to run only on a set number of nodes
in the Docker cluster, because those nodes
have been labeled as being PCI compliance.
So, that's how you use labels in Docker Swarm.