Restart one service in docker swarm stack Restart one service in docker swarm stack docker docker

Restart one service in docker swarm stack


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.


Scale to 0 and back up:

docker service scale myservice=0docker service scale myservice=10


Looking at the docker stack documentation:

Extended description

Create and update a stack from a compose or a dab file on the swarm

From this blog article: docker stack works in a similar way as docker compose. It’s idempotent. If the stack is already deployed, docker stack deploy will restart only those services which has the digest or tag that is updated:

docker stack process

From my experience, when I deploy the same stack again with one service changing, only the updated service will be restarted.

BUT... there seems to be some limitations to changes that are taken into account (some report bugs with image tags), so give it a try and see if works as expected.

You can also use service update if you want to be sure that only targeted service if updated with your changes.

You can also refer to this similar SO QA.