I am trying to use nginx-proxy with Docker Swarm mode. I have a stack for nginx-proxy and a stack for a whoami container which is replicated 3 times.
THe problem is that when I query the cluster, I always get response from the same whoami. When I hit docker service scale whoami_whoami=1
then nginx replies with 503
status code which means it keeps asking one of the removed replicas.
# proxy.yml
version: '3.8'
networks:
proxy:
driver: overlay
name: proxy
services:
nginx:
image: jwilder/nginx-proxy:latest
networks:
- proxy
environment:
- HTTPS_METHOD=noredirect
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
# - ${CLU_ROOT}/proxy/certs:/etc/nginx/certs:ro
ports:
- 80:80
# - 443:443
deploy:
placement:
constraints:
- node.role == manager
# whoami.yml
version: '3.8'
networks:
proxy:
external: true
services:
whoami:
image: jwilder/whoami:latest
networks:
- proxy
environment:
- VIRTUAL_HOST=whoami.dev.interne.eseo.fr
deploy:
replicas: 3
I was thinking that nginx will send requests to "whoami" and that it was the role of Swarm to balance between replicas. Am I wrong ?
On the other hand, when I publish the port 8000
of the whoami service and hit: while sleep 1; do clear; curl whoami....:8000; done
then every replies come from a different replica.
Thanks in advance