How to update docker stack without restarting all services
Asked Answered
A

4

20

I have a swarm cluster wherein different technology dockers are deployed. (Zookeeper, Kafka, Elastic, Storm and custom web application)

Web application goes under tremendous changes and have to update the stack everytime web docker changes. Once in a while there will be updates to Elasticsearch image.

When i run docker stack deploy, it goes and restarts all existing docker services which are not even changed. This hampers whole stack and there is a downtime for whole application. Docker stack does not have option of update.

Someone has solution for this?

Agram answered 18/5, 2017 at 15:30 Comment(1)
Actual question for me, but without answer...Riflery
D
12

docker service update --image does the trick.

Check the docker service update docs.

Dismiss answered 18/5, 2017 at 15:35 Comment(5)
docker service will update individual image. Everytime i need to specify which image needs to be updated. That will be really painful task.Agram
Am looking for solution wherein docker stack just updates the images which are modified and not the whole stackAgram
When I do docker stack deploy uneffected containers do not change. Could it be that you pulled newer versions of the images on your machine? But the only way I know that allows you to be 100% sure only one service is affected is docker service update...Dismiss
This works for me. docker service update --image demo.net/library/cf demo_webCaliphate
docker stack deploy updates not only images, but environment variables, networks, etc.Riflery
D
3

Redeploying the stack with changed configuration(docker-compose.yml file) solves the problem see https://docs.docker.com/engine/reference/commandline/stack_deploy/#extended-description. There they stated "Create and update a stack from a compose or a dab file on the swarm." Also i dont see any command like 'docker stack update '. So this can solve the problem.

Deerhound answered 16/8, 2018 at 6:38 Comment(3)
The question was: "[...] update docker stack without restarting all services"Blueing
Does this command "restart only changed" services, or restarts all of the servics regardless of the changes?Remove
This command recreates all containers, so it restarts them.Riflery
N
3

Since API 1.30 (see documentation) you can use the --resolve-image flag with changed value as follow:

docker stack deploy -c my_compose.yml --resolve-image changed my_stack

It will only update services that configuration has changed in the compose.

Nonjuror answered 4/11, 2023 at 11:3 Comment(1)
its default option is always and go for reading changes if there is .Brigitte
J
1

If you have docker stack created from compose.yml and you need to re-deploy only one service from stack, just do this:

docker service rm <your-service>

and then:

docker stack deploy -c compose.yml <stack-name>

And you just will update your stack, not recreate all services.

Jacobean answered 24/1, 2023 at 11:18 Comment(1)
after update image and push it to registry, there is no need to remove service and deploy, only run deploy read the new image and update its related containers.Brigitte

© 2022 - 2025 — McMap. All rights reserved.