Get the App
SLTechnology News&Howtos  ›  Servers  › 

How docker swarm runs the specified container on the specified node

Shulou Source: shulou.com Published: 2022-06-02 02:45:19 09月26日 Update

Describe the problem

For example, we have three docker host of worker1,worker2,worker3 plus a manager1 (which is the master of swarm) to manage them.

If you docker service create a container directly on the manager1, such as the nginx container, then master will decide which node to choose as the host for the nginx container to run.

What if I want the nginx container to run only on top of worker1?

Solution

Simply put, tag each node.

Docker node update-label-add func=nginx worker1

The above sentence means that master has labeled worker1's docker as nginx. Func and nginx are key-value pairs that you can set by yourself.

Then, when running docker service create, specify the-constraint parameter

Docker service create-- name my_nginx-- constraint 'node.labels.func = = nginx' nginx

In this way, the nginx container will be launched on worker1 rather than on other node.

Supplement

My curiosity made me do a bad job. After I tagged worker1 as func=nginx, I deliberately wrote node.labels.func = = nginx111 on the constraint parameter of docker service create.

At this point, you can see that service is registered with both docker service ls and docker service ps nginx, but its CURRENT STATE shows Pending, and there is no node assigned to it.

I didn't stop the service, and then I wrote the tag of worker2 as nginx111, miraculously, I started the nginx container on worker2 myself. Master is still very smart.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Tags: Container label run parameter that is time curiosity three content function miracle curiosity what to do meaning I want solution intelligence solution or this sentence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Apple Microsoft NVidia