Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How docker swarm runs the specified container on the specified node

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report