Skip to content

Traefik frontend rules

Traefik frontend rules are configuration directives used to define how incoming traffic is routed to specific services.^[Traefik.md] When using Traefik with Docker, these rules are typically assigned to containers via [[Docker]] labels.^[Traefik.md]

Frontend Rule Configuration

The primary frontend rule is defined using the label traefik.basic.frontend.rule.^[Traefik.md] A common use case is directing traffic based on the requested domain name.

Host-based routing For example, to route traffic for a specific domain, the rule is formatted as Host:domain2.com.^[Traefik.md]

labels:
  - "[Traefik](<./traefik.md>).basic.frontend.rule=Host:domain2.com"

Frontend rules often work in conjunction with other labels to fully configure the service access point.^[Traefik.md]

  • Port: The internal container port is specified using traefik.basic.port (e.g., 8080).^[Traefik.md]
  • Protocol: The protocol can be defined, such as traefik.basic.protocol=http.^[Traefik.md]
  • Network: Attaching the container to a specific network (e.g., traefik.docker.network=web) is required for Traefik to reach the service.^[Traefik.md]
  • Enable: The service must be enabled with traefik.enable=true.^[Traefik.md]

Sources