1

我的堆栈具有以下配置:

api:
  deployment_strategy: every_node
  environment:
    - 'DATABASE_URL=postgresql://.....'
    - REDIS_HOST=redis
  image: 'image/image:latest'
  links:
    - redis
  ports:
    - '5000:5000'
lb:
  image: 'dockercloud/haproxy:latest'
  links:
    - api
  ports:
    - '80:80'
  privileged: true
  roles:
    - global

这是 haproxy 输出

2017-05-26T12:00:51.752500376Z INFO:haproxy:dockercloud/haproxy 1.6.6 has access to the Docker Cloud API - will reload list of backends  in real-time
2017-05-26T12:00:51.752599249Z INFO:haproxy:dockercloud/haproxy PID: 5
2017-05-26T12:00:51.883065649Z INFO:haproxy:=> Add task: Websocket open
2017-05-26T12:00:52.884078353Z INFO:haproxy:=> Executing task: Websocket open
2017-05-26T12:00:52.884105435Z INFO:haproxy:==========BEGIN==========
2017-05-26T12:00:53.364820267Z INFO:haproxy:Linked service: API(d73c0091-ae4f-43b8-a3a8-ea11a276652e)
2017-05-26T12:00:53.364872613Z INFO:haproxy:Linked container: API_1(3f981340-9b04-4105-8876-2ad1e5521f5c)
2017-05-26T12:00:53.365695674Z INFO:haproxy:HAProxy configuration:
2017-05-26T12:00:53.365705363Z global
2017-05-26T12:00:53.365708753Z   log 127.0.0.1 local0
2017-05-26T12:00:53.365712075Z   log 127.0.0.1 local1 notice
2017-05-26T12:00:53.365715245Z   log-send-hostname
2017-05-26T12:00:53.365718228Z   maxconn 4096
2017-05-26T12:00:53.365721207Z   pidfile /var/run/haproxy.pid
2017-05-26T12:00:53.365724305Z   user haproxy
2017-05-26T12:00:53.365727513Z   group haproxy
2017-05-26T12:00:53.365730447Z   daemon
2017-05-26T12:00:53.365733783Z   stats socket /var/run/haproxy.stats level admin
2017-05-26T12:00:53.365736704Z   ssl-default-bind-options no-sslv3
2017-05-26T12:00:53.365746260Z   ssl-default-bind-ciphers xxxxxx
2017-05-26T12:00:53.365752089Z defaults
2017-05-26T12:00:53.365755064Z   balance roundrobin
2017-05-26T12:00:53.365758035Z   log global
2017-05-26T12:00:53.365761046Z   mode http
2017-05-26T12:00:53.365764045Z   option redispatch
2017-05-26T12:00:53.365767032Z   option httplog
2017-05-26T12:00:53.365769951Z   option dontlognull
2017-05-26T12:00:53.365775842Z   option forwardfor
2017-05-26T12:00:53.365780388Z   timeout connect 5000
2017-05-26T12:00:53.365793420Z   timeout client 50000
2017-05-26T12:00:53.365796603Z   timeout server 50000
2017-05-26T12:00:53.365799585Z listen stats
2017-05-26T12:00:53.365802356Z   bind :1936
2017-05-26T12:00:53.365805270Z   mode http
2017-05-26T12:00:53.365808233Z   stats enable
2017-05-26T12:00:53.365811235Z   timeout connect 10s
2017-05-26T12:00:53.365814235Z   timeout client 1m
2017-05-26T12:00:53.365817155Z   timeout server 1m
2017-05-26T12:00:53.365827005Z   stats hide-version
2017-05-26T12:00:53.365830160Z   stats realm Haproxy\ Statistics
2017-05-26T12:00:53.365833322Z   stats uri /
2017-05-26T12:00:53.365837063Z   stats auth stats:stats
2017-05-26T12:00:53.365839909Z frontend default_port_80
2017-05-26T12:00:53.365842760Z   bind :80
2017-05-26T12:00:53.365845760Z   reqadd X-Forwarded-Proto:\ http
2017-05-26T12:00:53.365848857Z   maxconn 4096
2017-05-26T12:00:53.365851745Z   default_backend default_service
2017-05-26T12:00:53.365854664Z backend default_service
2017-05-26T12:00:53.365857581Z   server API_1 10.7.0.2:5000 check inter 2000 rise 2 fall 3
2017-05-26T12:00:53.365886854Z INFO:haproxy:Launching HAProxy
2017-05-26T12:00:53.368391859Z INFO:haproxy:HAProxy has been launched(PID: 12)
2017-05-26T12:00:53.368498117Z INFO:haproxy:===========END===========

当我访问 haproxy IP 时,我进入ERR_CONNECTION_REFUSEDChrome 并且 API 服务日志为空,但是当我在端口 5000 上访问 haproxy 时,是的,请求到达了我的 API。
我觉得这很奇怪,因为我认为 HAProxy 会为我做这个路由。我错过了什么吗?也许绑定80:5000

4

1 回答 1

0

这个非常简单的例子对我有用:

api:
  image: nginx

lb:
  image: 'dockercloud/haproxy:latest'
  links:
    - api
  ports:
    - '80:80'
  privileged: true

(没有这roles部分,因为我没有使用 docker cloud)

...
lb_1   | INFO:haproxy:HAProxy has been launched(PID: 13)
lb_1   | INFO:haproxy:===========END===========
api_1  | 172.17.0.3 - - [26/May/2017:12:40:36 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" "172.17.0.1"
...

也许绑定80:5000?

你不应该。访问 :80 应该足够了,然后 haproxy 完成剩下的工作。

于 2017-05-26T12:30:20.127 回答