[英]Running Services on Specific Nodes with Docker Swarm
I'm new to docker swarm and looking to set containers to run on a specific node in the swarm.我是 docker 群的新手,希望将容器设置为在群中的特定节点上运行。 For example, I have the following nodes:
例如,我有以下节点:
Manager
Worker1
Worker2
And I have a couple services listed in a compose yml similar to:我在 compose yml 中列出了一些服务,类似于:
services:
my_service:
image: my_image
container_name: my_container_name
networks:
- my_network
my_service2:
image: my_image2
container_name: my_container_name2
networks:
- my_network
How can I make it so that my_service only runs on Worker1 and my_service2 only runs on Worker2?如何使 my_service 仅在 Worker1 上运行而 my_service2 仅在 Worker2 上运行?
UPDATE:更新:
I managed to find the solution.我设法找到了解决方案。 Can specify deployment constraints as shown below.
可以指定部署约束,如下所示。
my_service:
image: my_image
container_name: my_container_name
networks:
- my_network
deploy:
placement:
constraints:
- node.hostname == Worker1
my_service2:
image: my_image2
container_name: my_container_name2
networks:
- my_network
deploy:
placement:
constraints:
- node.hostname == Worker2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.