Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traefik gateway timeout for service with multiple networks

I use traefik as reverse proxy with a number of docker-based apps; each has a distinct network which it shares with traefik. Everything works.

Then I deployed another app, which has two networks: one shared with traefik, and one with its database. Sometimes it works, and sometimes I get a Gateway Timeout. This is really confusing, because it works for a while, fails, I restart traefik, it works again, fails, etc.

What could be the cause?

like image 979
lonix Avatar asked Sep 19 '25 20:09

lonix


1 Answers

Apparently traefic forwards traffic in round robin fashion. So if traefik only shares one of two networks with the service, every other request will fail.

The solution is to specify which network traefik should use; it can be set globally or per-service.

App's docker-compose.yml:

networks:
  traefik-myapp:
    external: true
  postgres-myapp:
  redis-myapp:

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

Traefik's docker-compose.yml:

networks:
  traefik-app1:
  traefik-app2:
  traefik-myapp:                 # <-----------

services:
  traefik:
    # ...
    networks:
      - traefik-app1
      - traefik-app2
      - traefik-myapp            # <-----------
  # ...
like image 52
lonix Avatar answered Sep 21 '25 11:09

lonix