1

I have the following configuration for my stack:

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

and this is the haproxy output

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===========

when I access the haproxy IP, I get ERR_CONNECTION_REFUSED on Chrome and the API service logs is empty, but when I access the haproxy on port 5000, then yes, the request hits my API.
I found it very weird, because I thought that HAProxy would do this routing for me. Am I missing something? maybe bind 80:5000?

Luiz E.
  • 6,769
  • 10
  • 58
  • 98

1 Answers1

0

This very simple example is working for me:

api:
  image: nginx

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

(without the roles part because I'm not using 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"
...

maybe bind 80:5000?

You shouldn't. It should be enough accessing :80 and then haproxy do the rest.

Robert
  • 33,429
  • 8
  • 90
  • 94
  • I actually can't do this, since I'm using dockercloud haproxy: https://github.com/docker/dockercloud-haproxy – Luiz E. May 26 '17 at 12:36
  • I've just realized that. Let me review – Robert May 26 '17 at 12:39
  • @LuizE. can you check that example? – Robert May 26 '17 at 12:50
  • how are you running services? docker-compose complains about `roles` (I've never used docker-cloud) – Robert May 26 '17 at 12:54
  • yes, roles is a specific thing from docker-cloud. I thing its something related with the `api` backend , not really a haproxy thing...will investigate more – Luiz E. May 26 '17 at 12:56
  • Have you any news? @LuizE. – Robert May 27 '17 at 02:21
  • I think I may find the problem: HAproxy default mode is HTTP load balancing, but my rails server (puma) is binded to tcp. dockercloud's haproxy actually can load balance in tcp mode, but for some reason, didn't worked for me and I had no time to dig deeper. – Luiz E. May 27 '17 at 09:14