title: Bad gateway with traefik and docker swarm during service update
body: <p>I’m trying to use traefik with docker swarm but i’m having troubles during service updates. I run a <code>stack deploy</code> or <code>service update</code> the service goes down for some seconds</p>
  
  <p>How to reproduce:</p>
  
  <p>1 - Create a Dockerfile:</p>
  
  <pre><code>FROM jwilder/whoami
  RUN echo $(date) &gt; daniel.txt
  </code></pre>
  
  <p>2 - Build 2 demo images:</p>
  
  <pre><code>$ docker build -t whoami:01 .
  $ docker build -t whoami:02 .
  </code></pre>
  
  <p>3 - Create a docker-compose.yml:</p>
  
  <pre><code>version: '3.5'
  
  services:
    app:
      image: whoami:01
      ports:
        - 81:8000
      deploy:
        replicas: 2
        restart_policy:
          condition: on-failure
        update_config:
          parallelism: 1
          failure_action: rollback
        labels:
          - traefik.enable=true
          - traefik.backend=app
          - traefik.frontend.rule=Host:localhost
          - traefik.port=8000
          - traefik.docker.network=web
      networks:
        - web
  
    reverse-proxy:
      image: traefik
      command: 
        - "--api"
        - "--docker"
        - "--docker.swarmMode"
        - "--docker.domain=localhost"
        - "--docker.watch"
        - "--docker.exposedbydefault=false"
        - "--docker.network=web"
      deploy:
        replicas: 1
        restart_policy:
          condition: on-failure
        update_config:
          parallelism: 1
          failure_action: rollback
        placement:
          constraints:
            - node.role == manager
      networks:
        - web
      ports:
        - 80:80
        - 8080:8080
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
  
  networks:
    web:
      external: true
  </code></pre>
  
  <p>4 - Deploy the stack:</p>
  
  <pre><code>$ docker stack deploy -c docker-compose.yml stack_name
  </code></pre>
  
  <p>5 - Curl to get the service response:</p>
  
  <pre><code>$ while true ; do sleep .1; curl localhost; done
  </code></pre>
  
  <p>You should see something like this:</p>
  
  <pre><code>I'm adc1473258e9
  I'm bc82ea92b560
  I'm adc1473258e9
  I'm bc82ea92b560
  </code></pre>
  
  <p>That means the load balance is working</p>
  
  <p>6 - Update the service</p>
  
  <pre><code>$ docker service update --image whoami:02 got_app
  </code></pre>
  
  <p>The traefik respond with <code>Bad Gateway</code> when should be zero downtime.</p>
  
  <p>How to fix it?</p>