I'm playing around with docker-compose haproxy and nginx. What I'm trying to accomplish is that if I scale the nginx container to be
docker-compose scale nginx=2
the haproxy container also proxies the new nginx container. But somehow its not recognizing the new container.
Here are my configs:
docker-compose.yml:
version: '2.1'
services:
nginx:
image: 'bitnami/nginx:latest'
healthcheck:
test: "curl -f http://localhost/?healthcheck"
expose:
- "80"
haproxy:
image: haproxy
restart: always
depends_on:
nginx:
condition: service_healthy
links:
- nginx
ports:
- "80:80"
volumes:
- ./haproxy:/usr/local/etc/haproxy/
expose:
- "80"
haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
defaults
log global
mode http
option httplog
timeout connect 5000
timeout client 10000
timeout server 10000
frontend localnodes
bind 0.0.0.0:80
mode http
default_backend nodes
backend nodes
mode http
option forwardfor
balance roundrobin
server nginx nginx:80 check
option httpchk GET /?haproxyselfcheck
http-check expect status 200
What could I do to get haproxy to recognize the new container without just adding one more nginx into docker-compose file manually?
After doing some reasearch I found a solution to work with docker swarm. Docker swarm has its own load-balancer. But to reverse proxy to the services best fit seemed to be docker-flow-proxy from the legendary Victor Farcic https://github.com/vfarcic/docker-flow-proxy
One can then just add the new services to the proxy.