# App with multiple networks sometimes fails with "Gateway Timeout"

**URL:** https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167
**Category:** Traefik v2
**Tags:** docker
**Created:** [July 8, 2023, 8:40am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167 "2023-07-08T08:40:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)
#### Post date: [July 8, 2023, 8:40am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167/1 "2023-07-08T08:40:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [July 8, 2023, 8:46am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167/2 "2023-07-08T08:46:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)
#### Post date: [July 8, 2023, 8:59am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167/3 "2023-07-08T08:59:35Z")

</div>

Thanks.

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

`docker-compose.yml` for app "myapp":

```yml
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:

```yml
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? 🤔

---

<div class="post-metadata">

### Author: ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)
#### Post date: [July 8, 2023, 9:11am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167/4 "2023-07-08T09:11:10Z")

</div>

I found another [answer of yours](https://community.traefik.io/t/traefik-gateway-timeout/17889/6)...

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)
#### Post date: [July 11, 2023, 9:11am UTC](https://community.traefik.io/t/app-with-multiple-networks-sometimes-fails-with-gateway-timeout/19167/5 "2023-07-11T09:11:55Z")

</div>

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