Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to specify Container deployment Node in docker swarm Cluster

Shulou Source: shulou.com Published: 2022-06-02 02:05:32 10月03日 Update

This article introduces how to specify container deployment nodes in docker swarm cluster. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

In docker swarm clusters, containers are usually deployed randomly to each node by default. However, it is sometimes encountered in deployment that some services are specified on a special machine.

If this happens, we can take advantage of the deploy.placement.constraints attribute in the docker-compose.yml file

1. Specify a manager or work node

Deploy: replicas: 1 placement: constraints: # # commonly used to specify manager or work nodes-node.role = = worker

two。 Specify hostname

Deploy: replicas: 1 placement: constraints:-node.hostname = = docker1

3. Specify node label

Node label can label one or more machines, and then specify the node tag in the compose file, which can be deployed on the machine with the corresponding tag. The specific steps are as follows:

Now label all the node machines on the master node machine, and the command is as follows:

Docker node update-- label-add role= tag name hostname for example, I'm going to label a machine with the hostname docker1 with the label db docker node update-- label-add role=db docker1.

Then, configure the compose file

Deploy: replicas: 1 placement: constraints:-node.labels.role = = db

Commands to delete node tags

Docker node update-- label-rm role tag name

4. Specify node id

Check the id of node first, and the command is as follows:

Docker node ls

As shown in the figure:

Deploy: replicas: 1 placement: constraints:-node.id = = xy4ttvg3xqbvwu4lok2xpgmrc

5. According to the engine tag

Deploy: replicas: 1 placement: constraints:-engine.labels.operatingsystem==ubuntu 14.04 so much about how to specify container deployment nodes in the docker swarm cluster. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Tags nodes machines containers clusters hosts commands files contents names more help good special middle finger interests multiple guys buddies attributes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Shulou Technology MySQL Xiaomi