我正在尝试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
...
更多细节这里。
我错过了什么?
答案1
我不确定我理解其中的原因,但是depends_on
据称可以解决问题(haproxy
取决于 s app
)。我猜是它在启动时haproxy
缓存解析的内容。如果当时并非所有 s 都在运行,则它仅缓存正在运行的 IP。app
app