title: Docker swarm replicas on different nodes
body: <p>I'm using a docker-compose file version 3 with its deploy key to run a swarm (docker version 1.13) and I would like to replicate a service in order to make it resilient again single node failure.</p>
  
  <p>However, when I'm adding a deploy section like this:</p>
  
  <pre><code>deploy:
      replicas: 2
  </code></pre>
  
  <p>in my four node cluster I sometimes end up with both replicas scheduled on the same node. What I'm missing is a constraint that schedules the two instances on different nodes.</p>
  
  <p>I know that there's a <code>global</code> mode I could use but that would run an instance on every node, i.e. four instances in my case instead of just two.</p>
  
  <p>Is there a simple way to specify this constraint in a generic way without having to resort to a combination of <code>global</code> and a labels to keep additional instances away from?</p>
  
  <p>Edit: After trying it again I find containers to be scheduled on different nodes this time around. I'm beginning to wonder if I may have had a <code>'node.hostname == X'</code> constraint in place.</p>
  
  <p>Edit 2: After another service update - and without any placement constraints - the service is again being scheduled on the same node (as displayed by <a href="https://github.com/ManoMarks/docker-swarm-visualizer" rel="noreferrer" title="ManoMarks Visualizer">ManoMarks Visualizer</a>):</p>
  
  <p><a href="https://i.stack.imgur.com/xPNtT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xPNtT.png" alt="enter image description here"></a></p>