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?
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.
Updating the existing service, swarm will recreate all containers. For example, you can simply update a property of the service to archive restarting.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With