Bad gateway with almost all containers

Hi the community

I'm new to traefik configuration and I can't get it working as reverse proxy, always get the "bad gateway" error...
Looking for others topics, I wonder about some misconfiguration in my server (just a new Raspberry PI4 with debian 10 and docker + docker-compose)
Going to my new container with IP:port works, but try to access with doesn't work with error "bad gateway". I also added the port with label into my docker compose:

        - "traefik.http.routers.jeedom.rule=Host(``)"
        - ""

Also, when I add the "whoami" test container, this work, without forcing the port value into label...

My complete docker compose config

Is there something wrong in my config ? Thanks :slight_smile:

Hi, bad gateway usually indicates a problem communicating with your backend service. Have you enabled debug logging in traefik and checked the logs? You could be trying to establish a HTTP connection to an HTTPS port.

Only HTTP until now... I added debug messages, so, lot of text I'm not sure how to analyze, but it doesn't look like an error ?

time="2021-09-07T00:26:22+02:00" level=debug
 msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request"
  \"Accept-Encoding\":[\"gzip, deflate\"],
  \"User-Agent\":[\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36\"],

That's just the request and headers from your browser, there's more in there that could be a clue as to what is happening. Look for the router configuration for the jeedom service, make sure its pointing at the correct port. Make sure an entrypoint was chosen. After the request from your logs that you pasted you should also see where traefik forwarded the request to.

In your docker compose you don't need the port configuration for each service, that is for mapping a host port to a container port but in this case you're going to reverse proxy through traefik to the container. The container still listens on its configured port and is available inside the docker network (local_net). Point your loadbalancer at the port the service is listening on.

Jeedom is a php+apache container and the default port is 80 ... But traefik also listen to port 80, do you mean they both can use port 80 without conflict ? Another point is, I used the link to double-check that my container jeedom is up and running, that's why it is usefull to have different port mapping for each container.
I will dive deep into traefik logs tonight, looking for the correct | grep formula to catch the only relevant log, thanks for helping :slight_smile:

Each container has its own network stack. They have their own network interface, route table, ip address, etc. You can have many containers on the same system listening on port 80 as long as you're not trying to bind them all to the same host port.

If you want to leave 8084 you can but the Jeedum container is still listening on port 80 on its own interface. You'll need to point your load balancer at port 80 (container port) not port 8084 (host port).

1 Like

Hi @bronzevanish thanks for this help :slight_smile:
Now I can reach some containers, using the right port and not the "host" mapped port. That means, I can have several web servers listening port 80 into their own container, and Traefik can reach all of them (by hosname ? or by IP ? ) without having specific mapping.
I can let the host port mapping anyway if I want to check the container without traefik, using the host IP + specific container port.

Considering Traefik debug logs, there are few clue, just confirm that the request was begin / forwarding / completed, but, the error is due to "connection redused", it is the good url / port indeed, I need to investigate into the targeted container ?

msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request"
msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL"
msg="'502 Bad Gateway' caused by: dial tcp connect: connection refused"
msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request"

502 Bad Gateway and Connection refused usually means the port is not open. Either the IP isn't the right one for your container or 8581 is not the port the container is listening on. You should be able to reference the container by its name, jeedum, ofelia, etc. It "resolves" like DNS on the internal docker networks. Definitely check the logs in the container to see whats going on. Docker inspect the container to look at the network configuration.