I'm trying to make haproxy
proxy requests to a number of replicas:
docker-compose.yml
:
services:
haproxy:
image: haproxy:2.3-alpine
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
ports:
- 8888:80
app:
build: .
command: perl app.pl
init: true
deploy:
replicas: 10
haproxy.cfg
:
global
maxconn 1024
listen in
bind :80
server-template srv 10 app:8080 check
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
But it seems to see only some of the replicas:
$ docker compose up
...
app-3 | MyWebServer: You can connect to your server at http://localhost:8080/
haproxy-1 | [NOTICE] 094/155107 (1) : New worker #1 (8) forked
app-4 | MyWebServer: You can connect to your server at http://localhost:8080/
app-2 | MyWebServer: You can connect to your server at http://localhost:8080/
app-5 | MyWebServer: You can connect to your server at http://localhost:8080/
app-9 | MyWebServer: You can connect to your server at http://localhost:8080/
app-7 | MyWebServer: You can connect to your server at http://localhost:8080/
app-6 | MyWebServer: You can connect to your server at http://localhost:8080/
app-1 | MyWebServer: You can connect to your server at http://localhost:8080/
app-10 | MyWebServer: You can connect to your server at http://localhost:8080/
app-8 | MyWebServer: You can connect to your server at http://localhost:8080/
app-3 | d3757cd065b4
app-3 | d3757cd065b4
app-3 | d3757cd065b4
app-4 | 226419df4354
app-4 | 226419df4354
app-4 | 226419df4354
...
More details here.
What am I missing?
I'm not sure I understand the reason, but
depends_on
supposedly resolves the issue (haproxy
depends on theapp
s). My guess is thathaproxy
caches whatapp
resolves to when it starts. If not all theapp
s are running at that moment, it caches only the running IPs.