docker-library/haproxy

haproxy not binding frontend port with backend ports

hanzlahabib opened this issue · 1 comments

Hi, i just recently started playing with docker world, i tried mocking Load balancing using Docker, Docker-compose and haproxy,

Issue which i am facing is this:
I created docker image and started it, things work fine (With no haproxy config)
when i use docker-compose to make use of haproxy load balancing, it serve my application correctly but it don't map to any frontend PORT

as per config, i should be able to listen at PORT 8080 but it don't work,

i may be doing something wrong or there is some SElinux / firewall restricting my port binding,

here are my config files

Dockerfile content

FROM node:alpine
RUN pwd
WORKDIR /app
COPY /app .
RUN npm install
CMD ["npm", "run", "start"]

docker-compose.yml content

version : '3'
services:
  lb:
      image: haproxy
      ports: 
          - 8080:8080
      volumes: 
          - ./haproxy:/usr/local/etc/haproxy
  app1:
      image: lb-test
      environment:
          - PORT=1111
  app2:
      image: lb-test
      environment:
          - PORT=2222

haproxy.cfg content

frontend http
    bind *:8080
    mode http
    default_backend http
backend http
    mode http
    server s1 app1:1111
    server s2 app2:2222

I have these config on my repo you can fork/clone it from there and test on your end
github repo link

Thank you

What specific errors cause it to not be working correctly? Anything in the docker logs?

You might need to run it with
https://github.com/docker-library/docs/tree/master/haproxy#run-the-container

sysctls:
  net.ipv4.ip_unprivileged_port_start=0

https://docs.docker.com/compose/compose-file/compose-file-v2/#sysctls

You could also try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow. Since these repos aren't really a user-help forum