36

I just completed the beginners Docker tutorials and would like to know how to clean up.

I deployed a stack and with a few different service using the below command:

docker stack deploy --compose-file docker-stack.yml vote 

Is there away to stop all the containers associated with this stack, or do I have to stop them individually?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
spw
  • 575
  • 2
  • 5
  • 8

1 Answers1

53

You can remove a stack with:

docker stack rm vote

At present, this is still a detached operation that will take time to run in the background.


If for some reason you still want the stack and service definitions, you can scale the "replicated" services down to 0 replicas, and "global" services you can add a constraint that doesn't match any node.

docker service update --replicas 0 $service_name
docker service update --constraint-add node.labels.no_such_node=true $service_name
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 4
    I just wanted to mention that it can take a while (10-15 seconds) for all of the containers to stop. I thought that `docker stack rm` wasn't cleaning everything up, which is why I found this SO question. – FellowMD Jul 15 '17 at 14:54
  • 7
    Isn't `docker stack rm` also deleting the containers? Shouldn't there be a command to just stop them when needed? – Valerio Santinelli Dec 14 '17 at 11:32
  • 1
    Swarm mode orchestration has the objective to make the current state match your target definition. So "stop all the containers" brings your current state out of the target state goal and swarm will try to correct that. You could do this by changing your target, but that needs to be done per service. – BMitch Dec 14 '17 at 13:52
  • 2
    Following worked for me "global" deployments, Windows Docker Swarm `docker service update --constraint-add no_such_node==true $service_name` – mechDeveloper Sep 03 '20 at 08:32