Ask Your Question
0

Is it possible to place a container onto a particular node within a docker swarm?

asked 2022-01-12 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-01 14:00:00 +0000

woof gravatar image

Yes, it is possible to place a container onto a particular node within a Docker swarm using various methods:

  1. Placement constraints - With placement constraints, you can specify a particular node label or attribute to deploy your container onto. For example, you can use the following command to deploy a container onto a node with a particular label:

    docker service create --name myservice --constraint node.labels.mylabel==myvalue nginx:latest
    
  2. Node selector - You can also use the node selector to specify the nodes on which you want to deploy your container. You can use the following command to deploy a container onto a node with a specific hostname:

    docker service create --name myservice --node-selectors "node.hostname==myhostname" nginx:latest
    
  3. Docker stack deploy - When deploying a stack, you can specify a deployment target for each service. The target can be a specific node, a group of nodes or a placement constraint. You can use the following command to deploy a stack to a particular node:

    docker stack deploy --compose-file docker-compose.yaml --placement-pref "spread=node.labels.mylabel" mystack
    

Overall, using placement constraints, node selectors, or Docker stack deploy, you can confidently deploy your containers to specific nodes in your Docker swarm.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-12 11:00:00 +0000

Seen: 10 times

Last updated: Nov 01 '21