Duplicate routers and services when using both file and docker provider

Follow-up of Duplicate routers and services when using both file and docker provider · Issue #8453 · traefik/traefik · GitHub

@ldez Thanks for the info! :slight_smile:
Do you know if there is any way to disable Traefik's automatic router and service creation in any way?
I would rather define every router+service in the dynamic config file to lighten my docker-compose.yml file.

The main goal of Traefik is to manage dynamic architecture:

  • a container appears, Traefik detect it and create the configuration (based on labels)
  • a container disappears, Traefik detect it and remove the configuration

The file provider breaks this dynamic behavior.

The file provider, for the routing, has been introduced for only old architecture (VMs, bare metal servers, ...)

If you want to reduce the size of your Docker compose files, my recommendation is to use several Docker compose files.

The main goal of Traefik is to manage dynamic architecture:

Too bad my architecture is very static ^^

If you want to reduce the size of you Docker compose files, my recommendation is to use several Docker compose files.

I was hoping to avoid having to manage more files, but it looks like I can't avoid it.
Thanks for the suggestion :slight_smile:

Another way to reduce the size of your files is to define the default values used to create routers:

Example
version: '3.8'

services:
  duplicati:
    image: "duplicati/duplicati:linux-arm32v7-latest"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DOCKERCONFIG}/duplicati:/data
    labels:
      traefik.enable: true
      traefik.docker.network: docker_1dupli_web
    networks:
      1dupli_web:
      othernetwork:

  traefik:
    image: "traefik:v2.5"
    ports:
      - 60000:60000
    command:
      - --providers.docker.exposedByDefault=false
      - '--providers.docker.defaultrule=Host(`{{ .Name }}.MYDOMAIN.duckdns.org`)'

      - --entrypoints.websecure.address=:60000
      - --entrypoints.websecure.http.tls.certResolver=leresolver
      - '--entrypoints.websecure.http.tls.domains[0].main=MYDOMAIN.duckdns.org'
      - '--entrypoints.websecure.http.tls.domains[0].sans=*.MYDOMAIN.duckdns.org'

      - --certificatesresolvers.leresolver.acme.dnschallenge.provider=duckdns
      - --certificatesresolvers.leresolver.acme.email=test@example.com
      - --certificatesresolvers.leresolver.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
      - --certificatesresolvers.leresolver.acme.storage=/letsencrypt/acme.json
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DOCKERCONFIG}/traefik/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      DUCKDNS_TOKEN: XXXXXXXXXXXXXXXXXXXX
    networks:
      1dupli_web:

networks:
  othernetwork:
  1dupli_web:

I didn't know the default rule option, thanks for letting me know! :rocket:

However, it is quite strange that I cannot find any information about the normalize function from the default setting Host(`{{ normalize .Name }}`) of defaultrule in the 2 websites linked Go template and sprig template functions.

the normalize function is a Traefik internal function that replace all special chars with -.

2 Likes

Got it, thanks!

It is a bit strange to have a function in the default setting and no explanation in the docs of what it does.
But anyway, I got it working and my compose file is a bit lighter now.

Thank you very much for the help, and have a good night (or day?) :slight_smile:

1 Like

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