Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart one service in docker swarm stack

Does anyone know if there is a way to have docker swarm restart one service that is part of a stack without restarting the whole stack?

like image 875
tweeks200 Avatar asked Jun 28 '17 20:06

tweeks200


People also ask

How do I restart a docker in swarm node?

You can use the --force or -f flag with the docker service update command to force the service to redistribute its tasks across the available worker nodes. This causes the service tasks to restart.

Does docker swarm restart container?

Updating the existing service, swarm will recreate all containers. For example, you can simply update a property of the service to archive restarting.


1 Answers

Doing docker stack deploy again for me is the way to go to update services. As Francois' Answer, and also in my own experience, doing so updates only services that need to be updated.

But sometimes, it seems easier when testing stuff to only restart a single service. In my case, I had to clear the volume and update the service to start it like it was fresh. I'm not sure if there is downside to the method I will describe. I tested it on my development stack and it worked great for me.

Get the service id you want to tear down then use docker service update --force <id> to force the update of the service which effectively re-deploy it

$ docker stack services <stack_name> ID                  NAME              ... 3xrdy2c7pfm3        stack-name_api    ...  $ docker service update --force 3xrdy2c7pfm3 

The --force flag will force the service to update causing it to restart.

like image 157
Matt Avatar answered Sep 30 '22 16:09

Matt