我正在尝试haproxy
向多个副本发出代理请求:
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
但似乎只看到了一些复制品:
$ 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
...
更多详细信息请参见此处。
我缺少什么?
我不确定我是否理解原因,但
depends_on
据说可以解决问题(haproxy
取决于app
s)。我的猜测是haproxy
缓存app
启动时解析的内容。app
如果此时并非所有s 都在运行,则它仅缓存正在运行的 IP。