Question

Can't bind Anchor IP on haproxy docker container

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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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