Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.