Restart one service in docker swarm stack

tweeks200 picture tweeks200 · Jun 28, 2017 · Viewed 56.9k times · Source

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?

Answer

Matt picture Matt · Feb 13, 2018

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.