使用Docker
运行haproxy
时遇到问题。我目前无法连接到localhost之外的haproxy
统计信息页面。当我运行以下命令curl localhost:1337
时,我可以看到haproxy
统计信息页面。
当我尝试从外界访问该页面时,使用服务器的IP地址我不能。
正在运行docker ps
会显示以下内容:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3fea8e39543 demo-haproxy "haproxy -f /usr/loca" 21 hours ago Up 21 hours 0.0.0.0:1337->1337/tcp my-running-haproxy2
我的Dockerfile
相对简单:
# Dockerfile
FROM haproxy:1.5
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
EXPOSE 1337
我的haproxy.cfg
文件也很简单:
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 10000
timeout server 10000
listen stats *:1337
stats enable
stats uri /
frontend localnodes
bind 0.0.0.0:80
mode http
default_backend nodes
backend nodes
mode http
option forwardfor
balance roundrobin
server web01 127.0.0.1:80 check
option httpchk GET /
http-check expect status 200
如果有人对我做错了什么有任何想法,请告诉我。我的期望是,当我去my-server-ip-address:1337
时,haProxy应该出现。
修改
这是在Microsoft的Azure平台上运行的。我打开了1337端点:
我用来启动haproxy的命令如下:
docker run -d -p 1337:1337 --name my-running-haproxy2 demo-haproxy
以下是我的sudo iptables-save
:
# Generated by iptables-save v1.4.21 on Tue Aug 25 20:57:09 2015
*nat
:PREROUTING ACCEPT [95320:5717604]
:INPUT ACCEPT [50764:3044244]
:OUTPUT ACCEPT [18551:1256145]
:POSTROUTING ACCEPT [18552:1256185]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -s 172.17.0.1/32 -d 172.17.0.1/32 -p tcp -m tcp --dport 1337 -j MASQUERADE
-A DOCKER ! -i docker0 -p tcp -m tcp --dport 1337 -j DNAT --to-destination 172.17.0.1:1337
COMMIT
# Completed on Tue Aug 25 20:57:09 2015
# Generated by iptables-save v1.4.21 on Tue Aug 25 20:57:09 2015
*filter
:INPUT ACCEPT [404037:61914084]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [405912:87310852]
:DOCKER - [0:0]
-A INPUT -p udp -m udp --dport 68 -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A DOCKER -d 172.17.0.1/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 1337 -j ACCEPT
COMMIT
# Completed on Tue Aug 25 20:57:09 2015