Appearance
Docker Swarm 部署模式
HAProxy 可作为 Docker Swarm 的入口负载均衡层。
部署 HAProxy 服务
bash
docker service create --name haproxy --publish published=80,target=80 --publish published=443,target=443 --config source=haproxy.cfg,target=/usr/local/etc/haproxy/haproxy.cfg --constraint 'node.role == manager' haproxy:latestDocker Socket 动态发现
lua
-- 动态更新后端服务
local f = io.popen("docker service ps -q web")
local services = f:read("*all")
f:close()健康检查
bash
docker service create --health-cmd "curl -f http://localhost:8080/health || exit 1" --health-interval 5s --health-retries 3 nginx:alpine滚动更新
bash
docker service update --image haproxy:2.9 haproxy
docker service rollback haproxy