Hi everyone, I’m new on using haproxy and Docker and I’m having trubles setting up a web app with Docker-compose.
I am using an Node.js app listening on port 8001 and it connects on a local database mongodb on port 27017. I have created a Docker compose file for configuring a Docker environment with 3 serves of the app, the DB and the haproxy server.
version: “3”
services:
app1:
container_name: app1
restart: always
build: .
ports:
- “81:8001”
links:
- mongo
networks:
- my-net
app2:
container_name: app2
restart: always
build: .
ports:
- “82:8001”
links:
- mongo
networks:
- my-net
app3:
container_name: app3
restart: always
build: .
ports:
- “83:8001”
links:
- mongo
networks:
- my-net
mongo:
container_name: mongo
image: mongo
ports:
- “27017:27017”
networks:
- my-net
haproxy:
build: ./haproxy
container_name: haproxy
links:
- app1
- app2
- app3
ports:
- “80:80”
- “8404:8404”
networks:
- my-net
networks:
my-net:
name: my-net
driver: bridge
the docker files for the haproxy is this:
FROM haproxytech/haproxy-alpine:2.4
COPY haproxy.conf /usr/local/etc/haproxy/haproxy.conf
and the docker file for the apps is the following:
FROM node:13-alpine
RUN mkdir -p /home/app
COPY ./nosql_practica4_bbdd-main /home/app
WORKDIR /home/app
RUN npm install
RUN npm run seed
CMD [“npm”, “start”]
EXPOSE 8001
The app is working if I type the ports on the browser but the haproxy isn’t working and on the logs it shows this error:
[ALERT] (8) : backend ‘app’ has no server available! docker
the haproxy.conf is the following:
global
stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
log stdout format raw local0 info
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 10000
timeout server 10000
frontend balancer
bind 0.0.0.0:80
mode http
default_backend apps
backend apps
mode http
balance roundrobin
server app1 app1:8001 check
server app2 app2:8001 check
server app3 app3:8001 check
anyone can help me understand what I have done wrong?