简体   繁体   中英

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. For example, I have the following nodes:

Manager
Worker1
Worker2

And I have a couple services listed in a compose yml similar to:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM