In reading the documentation for Docker Swarm 1.12 there is a section describe how to configure HAProxy to load balance traffic to swarm hosts.
https://docs.docker.com/engine/swarm/ingress/#/configure-an-external-load-balancer
If I understand Docker Swarm > 1.12 there shouldn't be a need to setup a load balancer in this way because Swarm has an internal load balancer and DNS.
Wouldn't a proper approach be to stand up a reverse proxy to the service name (DNS alias) and let the Swarm load balancer do the work?
For example in nginx you could do:
location /somepath/ {
proxy_read_timeout 900;
proxy_pass http://service-name/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
My assumption is that the service is deployed to a private network overlay and the service that needs to be exposed externally is deployed to the private network and a proxy network where the nginx or haproxy service is also deployed.
docker service create
--name recurrence-service \
--replicas 3 \
--network my-service \
--network proxy \
mycompany/my-web-server