Luke101
Luke101

Reputation: 65268

How to specify a manager leader in a docker swarm constraint

I am aware I can manually a constraint to a leader node. But, there may already be a built-in way to specify a leader node in a swarm.

Basically, I need to prevent containers from running on the leader node. They can run anywhere else except the leader. Is there a built in way to specify a leader node in the constraint?

Upvotes: 2

Views: 3888

Answers (1)

BMitch
BMitch

Reputation: 263996

To prevent containers from running on a node, you can do this for all containers using:

docker node update --availability drain $your_node_name

To do this for a single service, you can add a constraint on the node type:

docker service create --constraint 'node.role==worker' --name $your_service $image_name

I don't think there's any way to do this on only the leader with a group of managers, it's all or none. You may be able to script something external that checks the current leader and updates node labels.

Upvotes: 2

Related Questions