"No route to host" issue with deploying Haproxy and Apache with docker-compose

Hello,

I’m new to docker and for the last few days I’m trying to figure out how to make HAproxy and Apache (or Nginx) work together. My goal is to have HaProxy as a load-balancing server for 2 webservers. I was able to succesfuly build 3 containers with docker-compose but there seems to be an issue with connection between HaProxy and webserves. Not really sure what I’m missing.

I’m using this configuration:


I’m running it on Centos 8.

The issue:

[john@centos8a 12:21:02 haproxy_nginx]$ docker-compose up
Creating network "haproxy_nginx_default" with the default driver
Creating web1 ... done
Creating web2 ... done
Creating haproxy ... done
Attaching to web1, web2, haproxy
web1       | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.27.0.2. Set the 'ServerName' directive globally to suppress this message
web1       | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.27.0.2. Set the 'ServerName' directive globally to suppress this message
web1       | [Thu Jan 30 11:21:05.898867 2020] [mpm_event:notice] [pid 1:tid 140151592633472] AH00489: Apache/2.4.41 (Unix) configured -- resuming normal operations
web1       | [Thu Jan 30 11:21:05.898997 2020] [core:notice] [pid 1:tid 140151592633472] AH00094: Command line: 'httpd -D FOREGROUND'
web2       | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.27.0.3. Set the 'ServerName' directive globally to suppress this message
web2       | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.27.0.3. Set the 'ServerName' directive globally to suppress this message
web2       | [Thu Jan 30 11:21:06.293907 2020] [mpm_event:notice] [pid 1:tid 139994078790784] AH00489: Apache/2.4.41 (Unix) configured -- resuming normal operations
web2       | [Thu Jan 30 11:21:06.294215 2020] [core:notice] [pid 1:tid 139994078790784] AH00094: Command line: 'httpd -D FOREGROUND'
haproxy    | [NOTICE] 029/112106 (1) : New worker #1 (6) forked
haproxy    | [WARNING] 029/112107 (6) : Server http-out/web1 is DOWN, reason: Layer4 connection problem, info: "No route to host", check duration: 1047ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy    | [WARNING] 029/112108 (6) : Server http-out/web2 is DOWN, reason: Layer4 connection problem, info: "No route to host", check duration: 1058ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy    | [ALERT] 029/112108 (6) : backend 'http-out' has no server available!

Someone could help me here with this, please?

Hi,
I meet the same problem. I found it seems to be cause by firewalld. So I disable firewalld and using nftables (for my preference). And it seems work.
You may need to config nat on nftables. But I found that docker seems to help you to do the nat, so I just restart docker.

Oh … yes. I just oversaw you’re running CentOS 8…
Docker CE is officially not supported on Red Hat Enterprise Linux (RHEL) 8 or CentOS 8. The Red Hat’s officially recommended way to manage containers on RHEL 8 and CentOS 8 is Podman. Podman is basically a replacement for Docker on RHEL 8 and CentOS 8. Docker images are compatible with Podman though. So, moving to Podman should not be too hard.

On top, firewalld is very know to cause problems with docker container communication. You should disabe it and/or switch to iptables -> https://serverfault.com/questions/987686/no-network-connectivity-to-from-docker-ce-container-on-centos-8