title: Docker swarm mode: scale down a node and remove services
body: <p>I have set of tasks for given service <code>t1, t2, ..., tk</code> across nodes <code>N1, N2, ...Nw</code>.</p>
  
  <p><strong>Due to lower usage, I do not need as many tasks as <code>k</code>.
  I need only <code>l</code> tasks (<code>l &lt; k</code>).</strong></p>
  
  <p><strong>In fact, I do not need <code>w</code> nodes so I want to start removing machines and pay less. Removing one machine at a time is fine.</strong></p>
  
  <p>Each service has its own state.
  The services are started in <a href="https://docs.docker.com/engine/reference/commandline/service_scale/" rel="nofollow noreferrer" title="replicated mode">replicated mode</a>.</p>
  
  <p><strong>1) How can I remove a single node and force the docker swarm not to recreate the same number of tasks for the service?</strong></p>
  
  <p>Notes:</p>
  
  <ul>
  <li>I can ensure that no work is rerouted to tasks running on a specific node, so removing the specific node is safe.</li>
  <li>This is the easiest solution, I will end up with <code>w - 1</code> nodes and <code>l</code> services assuming that on the removed node was served <code>k - l</code> services.</li>
  </ul>
  
  <p>or</p>
  
  <p><strong>2) How can I remove specific containers (tasks) from docker swarm</strong> and keep the number of replicas of the service lower by the number of removed tasks?</p>
  
  <p>Notes:</p>
  
  <ul>
  <li>I assume that I already removed a node. The services from the node were redeployed to other nodes.</li>
  <li>I monitor myself the containers (tasks) which serve no traffic -> no state is needed to maintain</li>
  </ul>
  
  <p>or </p>
  
  <p><strong>3) Any other solution?</strong></p>