2

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?

Pavan Kishore
  • 91
  • 2
  • 9

3 Answers3

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
1

Based on the documentation you can use order property on your docker-service file

order: Order of operations during updates :

  1. stop-first (old task is stopped before starting new one)
  2. 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

https://docs.docker.com/compose/compose-file/#deploy

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.

https://technologyconversations.com/2017/01/31/blue-green-deployments-with-docker-services-running-inside-a-swarm-cluster/

German
  • 1,449
  • 12
  • 13