docker容器启动haproxy

1、在本地新增haproxy.cfg文件(本次haproxy.cfg文件路径为/root/haproxy.cfg),内容如下:

#----------------
# Global settings
#----------------
global
    log         127.0.0.1 local2
    maxconn     4000
    daemon
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 500
#-------------
#Stats monitor
#-------------
frontend stats_monitor
        bind    *:30001
        stats   enable
        stats   uri     /stats
        stats   auth    admin:admin
        stats   admin   if      TRUE
        stats   refresh 5s
        stats   realm   baison-test-Haproxy
#       stats   hide-version
#--------------------
#Application frontend
#--------------------
frontend        GEOGLOBE
bind    *:8080
#ACL#
acl map_acl path_reg -i /map/
#USE_BACKEND#
use_backend map_backend if map_acl
#map_begin#    
backend map_backend
balance roundrobin
mode http
server map_101 172.15.103.195:20001 check weight 1
#map_end#

2、使用Docker run启动容器

docker run -d -p 8080 -p 30001 --name haproxy -v /root/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro haproxy:1.9.11
原文地址:https://www.cnblogs.com/nihaorz/p/10783249.html