Traefik gateway timeout for service with multiple networks

744 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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            # <-----------
  # ...