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?
6 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.

- 10,633
- 3
- 46
- 49
-
1Does the `docker service update --force
` solution force reading the stack/compose file again? I am asking this because I do want to override the service container entrypoint once the full stack has already been deployed, but restarting the single service solely! – andreagalle Sep 14 '21 at 12:34 -
1It doesn't update containers running on worker nodes. However, it updates containers just on the manager node. – Rahman Oct 19 '21 at 08:16
-
ok, neither if I run the same command on each node? – andreagalle Oct 19 '21 at 08:53
-
did not work with **promiethus** to read its config file `yml` again – Shakiba Moshiri Oct 26 '21 at 07:26
Scale to 0 and back up:
docker service scale myservice=0
docker service scale myservice=10

- 8,276
- 5
- 44
- 36
-
4this one is the only one that actually forces a restart. Thanks! – the_ccalderon May 01 '18 at 00:29
-
1agree, just forcing an update didn't restart service for me, don't know why – Egor May 15 '18 at 08:37
-
Although this method does seem to stop the service but somehow the service remains lurking deep in the bowels of the beast. For example I get 'port already in use' when I scale down the service and try to spin another one that uses the same port. – netlander Nov 02 '20 at 10:46
-
this does not restart a service - and by restart I mean that service reads its configuration again - I tested on **prometheus** and did not work – Shakiba Moshiri Oct 26 '21 at 07:24
-
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:
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.

- 1
- 1

- 5,884
- 6
- 45
- 50
-
Thanks, this does work as expected. I'm actually looking to force a restart of one specific service (or the whole stack) in a rolling manner. Unfortunately some services I deal with have issue with cache invalidation and we find we need to remove/re-deploy to the stack to force the updates. Looking at the `service update` documentation I could add/remove `env` variables to fake it out if there's no built in way. – tweeks200 Jul 21 '17 at 18:36
-
Was just looking for the same thing - couldn't find any in the docs. – Morgan Kobeissi Aug 03 '17 at 08:53
-
1I just encounted following issue: `docker stack deploy` would not start a service (openldap). I could not find a log file. `docker-compose run
` would start the container without problem. Finally, `docker service update --force – rhoerbe Jun 05 '19 at 13:55`did work.
As per the example in the documentation for rolling updates:
$ docker service update --image redis:3.0.7 redis
However, that only works if your image is already on the local machines. If not then you need to use --with-registry-auth to send registry authentication details to the swarm agents. See details in the docker service update documentation.
$ docker service update --with-registry-auth --image redis:3.0.7 redis

- 897
- 7
- 17
To restart a single service (with rolling restart to avoid downtime in case the service has multiple replicas) in already configured, existing stack, you can do:
docker service update --force stack_service_name
I don't recommend running the same command again (in another shell) until this one completes (because otherwise the rolling restart isn't guaranteed; it might restart all replicas of that service).
The docker service update
command also checks for newer version of the image:tag you are trying to use.
If your registry requires auth, also pass --with-registry-auth
argument, like so:
docker service update --force --with-registry-auth stack_service_name
If you don't pass this argument, the service will still be restarted, but the check won't be made and the service will still use the old container image without pulling the new one first. Which might be what you want.
In case you want to also switch to different image tag (or completely different image), you can do it from here too, but remember to also change the tag in your docker-stack.yml
, or your next docker stack deploy
will revert it back to the verison defined there:
docker service update --with-registry-auth --force --image nginx:edge stack_service_name

- 1,140
- 9
- 19
remove it:
docker stack rm stack_name
redeploy it:
docker stack deploy -c docker-compose.yml stack_name

- 1,201
- 14
- 14
-
The accepted answer above works and does it in a rolling manner to avoid downtime – tweeks200 Jul 22 '19 at 17:25