Data from docker-compose in traefik.yml

I have some questions for beginners which I could not answer in the last days on google and I hope you can help me.

For a better overview I would like to insert either all labels from docker-compose.yml into traefik.yml or vice versa. I don't know which variant is better.

So far these are my files:

docker-compose.yml

version: '3.8'

services:
  traefik:
    image: "traefik:latest"
    container_name: traefikproxy
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik.yml:/traefik.yml:ro
      - ./shared-config.yml:/shared-config.yml
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      - "traefik.http.routers.traefik.rule=Host(`traefik.localdomain.tld`)"
	  
	  #Auth in a separate file, easier because the $ does not need to be masked
      - "traefik.http.routers.traefik-secure.middlewares=traefik-auth@file"
	  # Auth in docker-compose.yml
      #- "traefik.http.middlewares.traefik-auth.basicauth.realm=Authenticate for Traefik"
      #- "traefik.http.middlewares.traefik-auth.basicauth.users=user:$$apr1$$7ciH.Uzt$$DUqDgmpLmFE2Fm7Z7VaMe/"
	  #- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
      - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik.localdomain.tld`)"
      - "traefik.http.routers.traefik-secure.tls=true"
      #- "traefik.http.routers.traefik-secure.tls.certresolver=http"
      - "traefik.http.routers.traefik-secure.service=api@internal"
    environment:
      - "TZ=Europe/Berlin"
    networks:
      - traefik_proxy

networks:
  traefik_proxy:
    external: true

traefik.yml

api:
  dashboard: true

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false
  file:
    filename: shared-config.yml

shared-config.yml

http:
middlewares:
traefik-auth:
basicAuth:
realm: "Traefik Authentication"
users:
- "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"
- "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"
- "user:$apr1$7ciH.Uzt$DUqDgmpLmFE2Fm7Z7VaMe/"

I now have the following questions:

  1. Is it better to add these "rules" to docker-compose.yml or all to traefik.yml?
  2. Would it also be possible to get basicAuth in the traefik.yml instead of a separate file?
  3. Is my configuration ok, or would it be good to adjust something?

Please excuse the many questions and thanks for any help

Koda

I feel that should answer it: https://docs.traefik.io/getting-started/configuration-overview/

@zespri
I have looked at the documentation over and over again. But I always see something new. Thanks.

Koda