How to configure (in dynamic way | docker compose file) some other service to see running traefik?

Hi all.

All my attempt refers to putting traefik and some services on localhost with https. I already got it with traefik with the configuration shown below

  1. my docker-compose traefik.yml file
version: '3.5'

networks:
  ntwkr_docker:
    external: true

services:
  reverse-proxy:
    image: traefik:v2.6
    container_name: wsl-traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    ports:
      # Web
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      # Map the static configuration into the container
      - ./traefik/config/static.yml:/etc/traefik/traefik.yml:ro
      # Map the dynamic configuration into the container
      - ./traefik/config/dynamic.yml:/etc/traefik/dynamic.yml:ro
      # Map the certificats into the container
      - ./traefik/certs:/etc/certs:ro
    networks:
      - ntwkr_docker

  1. my referred static.yml file
global:
  sendAnonymousUsage: false

api:
  dashboard: true
  insecure: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false

  file:
    filename: /etc/traefik/dynamic.yml
    watch: true

log:
  level: INFO
  format: common

entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"

  1. my referred dynamic.yml file
http:
  routers:
    traefik:
      rule: "Host(`traefik.docker.localhost`)"
      service: "api@internal"
      tls:
        domains:
          - main: "docker.localhost"
            sans:
              - "*.docker.localhost"
          - main: "domain.local"
            sans:
              - "*.domain.local"

tls:
  certificates:
    - certFile: "/home/marconobre/.pki/nssdb/local-cert.pem"
      keyFile: "/home/marconobre/.pki/nssdb/local-key.pem"

And the big question:

What is the syntax of a docker-compose.yml file to run another service that is perceived and redirected by traefik to be accessed with https://.docker.localhost in the same way as I access the traefik dashboard with https ://traefik.docker.localhost ?

1 Like

For every router you need a service.

The router and service can be created automatically by Configuration Discovery with provider.docker from labels (example) or you can declare it manually with loadbalancers.servers.url http target with provider.file.

Note you only really need the domains/main/sans stuff for wildcard certs. For regular certs the Host() is enough. When you provide a cert, you just need to enable TLS on entrypoint (globally) or directly on router.