我正在玩弄docker-compose haproxy和nginx。 我想要实现的是,如果我将nginx容器扩展到:
docker-compose scale nginx=2
haproxy容器也会代理新的nginx容器。 但是不知何故它无法识别新的容器。
这是我的配置:
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
我应该怎么做才能让haproxy识别新的容器,而不需要手动添加另一个nginx到docker-compose文件中?