Using node labels to constrain services
Labels are defined as key-value sets. We'll use the key env
(short for environment). At the moment, we don't need to label the nodes used for CD tasks since we are not yet running them as services. We'll change that in one of the chapters that follow. For now, we only need to label the nodes that will be used to run our services in the production-like environment.
We'll use the nodes swarm-test-2
and swarm-test-3
as our production-like environment so we'll label them with the key env
and the value prod-like
.
Let's start with the node swarm-test-2
:
docker node update \
--label-add env=prod-like \
swarm-test-2
We can confirm that the label was indeed added by inspecting the node:
docker node inspect --pretty swarm-test-2
The output of the node inspect
command is as follows:
ID: vq5hj3lt7dskh54mr1jw4zunb
Labels:
- env = prod-like
Hostname: swarm-test-2
Joined at: 2017-01-2123:01:40.557959238 +0000 utc
Status:
State:...