kerkerj
不知道標題該下啥…
前陣子因為工作需要,需要測試一個 web app 分布在多台機器下的狀況
想說使用 docker 來做這件事,但又懶得弄 nginx 的設定
稍微查了一下發現有 dockercloud/haproxy
我使用的情境是 web app * 3 + ha * 1 + redis * 1
web 使用了兩個 port 7788, 7789
但是不想讓 ha 把流量導去 7788,所以可以設定 EXCLUDE_PORTS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
redis: | |
image: redis | |
ports: | |
- "6379" | |
web1: | |
image: my_image:tag | |
environment: | |
- REDIS_URL=redis:6379 | |
- EXCLUDE_PORTS=7788 | |
links: | |
- redis | |
web2: | |
image: my_image:tag | |
environment: | |
- REDIS_URL=redis:6379 | |
- EXCLUDE_PORTS=7788 | |
links: | |
- redis | |
web3: | |
image: my_image:tag | |
environment: | |
- REDIS_URL=redis:6379 | |
- EXCLUDE_PORTS=7788 | |
links: | |
- redis | |
lb: | |
image: dockercloud/haproxy | |
links: | |
- web1 | |
- web2 | |
- web3 | |
environment: | |
- DOCKER_TLS_VERIFY | |
- DOCKER_HOST | |
- DOCKER_CERT_PATH | |
- STATS_PORT=1936 | |
- STATS_AUTH="auth:auth" | |
volumes: | |
- $DOCKER_CERT_PATH:$DOCKER_CERT_PATH | |
ports: | |
- 5566:80 # 透過 docker_ip:5566 可以連到 web app | |
- 7788:1936 # 透過 docker_ip:7788 可以連到 haproxy 的 stats page |
如此一來,在 docker-compse up
後,就可以透過 http://192.168.99.100:5566/
來連上了
並且可以透過 docker stats $(docker ps -q)
這個指令來觀察正在執行中的 containers 的基本 metrics~
快速簡單!