App with multiple networks sometimes fails with "Gateway Timeout"

My server has traefik (defined in a compose file), and multiple other apps (each in its own compose file). Each app's compose file defines a shared network; it is used by both the app and traefik. Everything works so far.

However, now I added another app (with its own compose file), and it needs multiple networks: a shared network (for it and traefik), one to be shared by it and the database, another for it and redis, etc.

For some reason, it sometimes works, and sometimes I get a Gateway Timeout error. It's really confusing - because it works for a while, then fails, I restart traefik, it works for a while, then fails, etc.

Any advice would be appreciated... thank you.

Set docker.network. If using compose, make sure to give the Docker network a name, otherwise it will have a project adapted name.

1 Like

Thanks.

Am I understanding you correctly, do you mean like this:

docker-compose.yml for app "myapp":

networks:
  traefik-myapp:        # <---
    external: true
  posgres-myapp:
  redis-myapp:

services:
  myapp:
  # ...
  networks:
    - traefik-myapp           # <---
    - posgres-myapp
    - redis-myapp
  labels:
    traefik.docker.network: traefik-myapp    # <----------- THIS

# ...

And docker-compose.yml for traefik itself:

networks:
  traefik-portainer:
  traefik-myapp:            # <---
  traefik-gitea:

services:
  traefik:
  # ...
  networks:
    - traefik-portainer
    - traefik-myapp            # <---
    - traefik-gitea

# ...

If so, why is this necesary when there are multiple networks for an app, and not when the app has only one network? And of course, how come it works sometimes and sometimes not? :thinking:

I found another answer of yours...

...forward traffic round robin. If Traefik only shares one network (of two) with the service, every other forward will fail.

If you set docker.network, Traefik will only use that network to forward traffic to. It can be set globally or per service.

I assume that's what's happening in my case too.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.