Skip to main content

Dynamic Configuration File/s

logo-traefik-proxy-logo.pngThe dynamic configuration contains everything that defines how the requests are handled by your system. This configuration can change and is seamlessly hot-reloaded, without any request interruption or connection loss.

How Traefik Loads the Dynamic Config File/s

Refer to the Static Configuration Post for context. Traefik loads the static.yaml, and within that file, the dynamic file(s) are referenced for loading.

To load your dynamic configurations, you can set them up in two ways. Either write all your dynamic content into a single file or split it into multiple files for better organization.

 

Example: Loading Configuration in One File

Needs to be set up in static.yaml. The /dynamic.yaml is the path inside the container and must be mounted using Docker Compose:

volumes:
  # Dynamic Configuration File
  - '/path/on/your/linuxhost/dynamic:/dynamic.yaml'

Example static.yaml:

providers:
  docker:
    exposedByDefault: false
    network: "management_net"
  swarm:
    network: "management_net"
  file:
    watch: true
    file: "/dynamic.yaml"

 

Example: Loading Multiple Configuration Files

This setup loads every file in the specified directory with the YAML format. The /dynamic/ path is the path inside the container and must be mounted using Docker Compose:

volumes:
  # Dynamic Configuration Folder
  - '/path/on/your/linuxhost/dynamic:/dynamic/'

Example static.yaml:

providers:
  docker:
    exposedByDefault: false
    network: "management_net"
  swarm:
    network: "management_net"
  file:
    watch: true
    directory: "/dynamic/"

 

Splitting Dynamic Files

Create multiple paths in your Traefik data folder. Assuming your base Traefik data folder is /mnt/glustermount/data/traefik_data, you can structure it like this:

mkdir -p /mnt/glustermount/data/traefik_data/dynamic
touch /mnt/glustermount/data/traefik_data/dynamic/http.middlewares.yaml
touch /mnt/glustermount/data/traefik_data/dynamic/http.routers.yaml
touch /mnt/glustermount/data/traefik_data/dynamic/http.services.yaml
touch /mnt/glustermount/data/traefik_data/dynamic/tls.options.yaml

Then you can write configurations into these files. Below are examples for each:

Example: http.middlewares.yaml

http:
  middlewares:
    my-secure-headers:
      headers:
        sslRedirect: true
        stsSeconds: 31536000
        stsIncludeSubdomains: true
        stsPreload: true

Example: http.routers.yaml

http:
  routers:
    my-router:
      rule: "Host(`example.com`)"
      entryPoints:
        - websecure
      service: my-service
      tls: {}

Example: http.services.yaml

http:
  services:
    my-service:
      loadBalancer:
        servers:
          - url: "http://192.168.1.10:8080"

Example: tls.options.yaml

tls:
  options:
    default:
      minVersion: VersionTLS12
      cipherSuites:
        - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
        - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384