mateeyow
By:
mateeyow

Can't bind Anchor IP on haproxy docker container

January 18, 2016 1.1k views
Networking Docker High Availability Load Balancing CoreOS Ubuntu

Hi! I'm trying to bind my droplet's anchor IP address to haproxy. Here's my haproxy.cfg file:

global
  maxconn 4096
  debug

defaults
  log     global
  mode    tcp
  option  tcplog
  option  dontlognull
  timeout connect 5000
  timeout client  50000
  timeout server  50000

frontend www
  bind    $ANCHOR_IP:80
  default_backend node-fedex

backend node-fedex
  balance leastconn
  server  app-1 $BACKEND_IP_1:8080 check
  server  app-2 $BACKEND_IP_2:8080  check

I am using Docker's official haproxy base image. And every time I run the container I get this error: Starting frontend www: cannot bind socket [10.15.0.40:80]. I can just bind the front-end with * but I just want it to bind to the anchor ip address then utilize the floating ip for high availability.

1 Answer

The Anchor IP, in this case 10.15.0.40, is not going to be available inside the container. By default Dockers are on their own bridge network. In the configuration file, you should bind to all interfaces inside the container.

global
  maxconn 4096
  debug

defaults
  log     global
  mode    tcp
  option  tcplog
  option  dontlognull
  timeout connect 5000
  timeout client  50000
  timeout server  50000

frontend www
  bind    *:80
  default_backend node-fedex

backend node-fedex
  balance leastconn
  server  app-1 $BACKEND_IP_1:8080 check
  server  app-2 $BACKEND_IP_2:8080  check

Then at run time, you will need to bind the container to the Anchor IP rather than the docker0 bridge network. In the example below example, I've built an image named "my-haproxy" from the simple Dockerfile:

docker build -t my-haproxy .
FROM haproxy:1.5
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

To launch this container bound to the Anchor IP, run:

  • docker run --rm --name haproxy-test -p 10.15.0.40:80:80 my-haproxy
Have another answer? Share your knowledge.