paul590
paul590

Reputation: 1435

can I use two hostname in my constraints on docker stack file?

I have a stack file in which I am trying to tell it to use either of two hostnames I am providing. is this possible? The service does not start with these variables however, when removing at least one of them, it works. Thank you for your help!

stack file:

deploy:
    placement:
        constraints:
            - node.hostname == myhost1
            - node.hostname == myhost2

Upvotes: 2

Views: 7242

Answers (1)

Metin
Metin

Reputation: 741

The placement constraints are AND chained.

Though, you could add node labels to both hosts and use the node label as placement constraint instead. I use the label "mycustomlabel=true" to illustrate the usage.

On a manager node:

docker node update --label-add mycustomlabel=true myhost1
docker node update --label-add mycustomlabel=true myhost2

Then use the node label as a placement constraint:

deploy:
    placement:
        constraints:
            - node.labels.mycustomlabel == true

Of course the label can have a key=value of your choosing. A node can have multiple node labels.

Upvotes: 6

Related Questions