I want to update docker swarm service without down-time. The problem is that I don't have enough resources to have service replication. Is there anyway to do this?
Asked
Active
Viewed 2,232 times
3 Answers
5
The default with swarm mode is to stop containers before starting new ones. There is a pull request (#30261) that was added in 17.05 to optionally start a new instance before stopping the old one. The syntax for this is:
docker service update --update-order start-first ...
This has not been added to updating stacks yet, you can track that request on issue #32586.

BMitch
- 231,797
- 42
- 475
- 450
-
I think this doesn't work as expected with the vip mode when you curl every second, you may get 502. – Hakan Özler Aug 12 '17 at 09:56
-
This is the correct answer ! and the best practice - thanks it's really help me – Yakir GIladi Edry Jan 05 '22 at 09:34
1
Based on the documentation you can use order property on your docker-service file
order: Order of operations during updates :
- stop-first (old task is stopped before starting new one)
- start-first (new task is started first, and the running tasks briefly overlap) (default stop-first)
and your docker service file will be like this
version: '3.4'
services:
nginx:
image: nginx
restart: always
deploy:
restart_policy:
condition: on-failure
update_config:
order: start-first
make sure you are using version 3.4+ to make it work

Bahaa Odeh
- 583
- 1
- 7
- 16
0
The type of deploy you want to do is called blue-green deployment. I recommend following the steps of this blog to do it.

German
- 1,449
- 12
- 13