Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务
[root@linux-node3 ~]# yum install pip*
[root@linux-node3 ~]# pip install docker-compose
vim haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 5000ms
timeout server 5000ms
listen stats
bind 0.0.0.0:1080
mode http
stats enable
stats hide-version
stats uri /stats
stats auth admin:admin
frontend balance
bind 0.0.0.0:80
default_backend web_backends
backend web_backends
mode http
option forwardfor
balance roundrobin
server web1 web1:80 check
server web2 web2:80 chec
vimdocker-compose.yml
web1:
image: nginx
volumes:
- /opt/index1.html:/usr/share/nginx/html/index.html
expose:
- 80
web2:
image: nginx
volumes:
- /opt/index2.html:/usr/share/nginx/html/index.html
expose:
- 80
haproxy:
image: haproxy
volumes:
- /opt/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
links:
- web1
- web2
ports:
- “7777:1080”
- “80:80”
准备2个html文件
index1.html
index2.html
[root@linux-node3 opt]# docker-compose up 生产加-d 后台启动
负载成功
反复刷新,就可以看出负载成功。
登录haproxy里看看。