Correct way to put app on traefik network?

Whats the correct way to deal with networks in a multi-container app?
In the following example there are 3 containers; db, memcached and seafile
Ordinarily without traefik involved, they are all a part of the 'seafile-net' network as defined in the docker-compose.yml file.

Traefik is attached to the network 'traefik', and so I have attached the main app in the seafile docker-compose.yml to the 'traefik' network, since I don't want the 'db' or the 'memcached' containers on that network. This means that the 'seafile' container is on 2 networks 'traefik' and 'seafile-net'.
This seems to work.... sometimes, not always, and so I have to bring the app up and down until it works. This is the case with other apps I have, which are composed in a similar manner.

If I place all of the containers in the app on the 'traefik' network, everything works fine, first time.
I would just like to know, what is the correct way to deal with this?

services:
  db:
    image: mariadb:10.11
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD="mypassword"  # Required, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
      - MARIADB_AUTO_UPGRADE=1
    volumes:
      - /opt/seafile/seafile-mysql/db:/var/lib/mysql  # Required, specifies the path to MySQL data persistent store.
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    networks:
      - seafile-net
#      - traefik
  memcached:
    image: memcached:1.6.18
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net
#      - traefik
  seafile:
    image: seafileltd/seafile-mc:11.0-latest
    container_name: seafile
    ports:
      - "8081:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.seafile.rule=Host(`seafile.mydomain.xyz`)" # && (PathPrefix(`/login`))"
      - "traefik.http.routers.seafile.tls=true"
      - "traefik.http.routers.seafile.entrypoints=websecure"
      - "traefik.http.routers.seafile.tls.certresolver=myresolver"
      - "traefik.http.services.seafile.loadbalancer.server.port=80"
    volumes:
      - /tragopan-share/seafile:/shared   # Required, specifies the path to Seafile data persistent store.
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD="mypassword"  # Required, the value should be root's password of MySQL service.
      - TIME_ZONE=Etc/UTC  # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=admin@mydomain.xyz # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=mypassword     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=seafile.mydomain.xyz # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
    networks:
      - traefik
      - seafile-net

networks:
  seafile-net:
  traefik:
    external: true

This is a regular question on this forum:

When using multiple Docker networks with Traefik and target services, you should to set docker.network in static config with provider (doc) or in dynamic config (doc).

Thanks, for anyone in future - I fixed this by adding the label "traefik.docker.network=traefik" to my docker-compose.yml in the 'seafile' container section (the only container in the stack with traefik enabled.

seafile:
    image: seafileltd/seafile-mc:11.0-latest
    container_name: seafile
    ports:
      - "8081:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.seafile.rule=Host(`seafile.mydomain.xyz`)"
      - "traefik.http.routers.seafile.tls=true"
      - "traefik.http.routers.seafile.entrypoints=websecure"
      - "traefik.http.routers.seafile.tls.certresolver=myresolver"
      - "traefik.http.services.seafile.loadbalancer.server.port=80"
      - "traefik.docker.network=traefik"
1 Like

I stumbled upon this post as been searching for a solution to make Seafile work behind Traefik. This point about adding docker.network label to container (or alternatively to static config yml) on Traefik proxy network is crucial and worked for me too. Huge thanks!