Skip to content

Traefik Docker label configuration

Traefik utilizes Docker labels to configure dynamic routing and service discovery for containers running within a Docker network.^[400-devops-03-containerization-traefik.md]

Configuration Syntax

Configuration is applied by adding a labels section to the docker-compose.yml file of a service.^[400-devops-03-containerization-traefik.md]

Basic Labels

The following labels are commonly used to enable and configure routing:

  • Network Attachment: traefik.docker.network=web attaches the container to the specified network (in this example, the web network).^[400-devops-03-containerization-traefik.md]
  • Enable: traefik.enable=true activates Traefik for the specific container.^[400-devops-03-containerization-traefik.md]
  • Frontend Rule: traefik.basic.frontend.rule=Host:domain2.com defines the routing rule, such as matching a specific domain name (e.g., domain2.com).^[400-devops-03-containerization-traefik.md]
  • Port: traefik.basic.port=8080 specifies the internal port on the container that Traefik should forward traffic to.^[400-devops-03-containerization-traefik.md]
  • Protocol: traefik.basic.protocol=http sets the protocol to use for the communication (e.g., http).^[400-devops-03-containerization-traefik.md]

Example

The following YAML snippet demonstrates a typical configuration within a docker-compose.yml file^[400-devops-03-containerization-traefik.md]:

labels:
  - "[Traefik](<./traefik.md>).docker.network=web"
  - "[Traefik](<./traefik.md>).enable=true"
  - "[Traefik](<./traefik.md>).basic.frontend.rule=Host:domain2.com"
  - "[Traefik](<./traefik.md>).basic.port=8080"
  - "[Traefik](<./traefik.md>).basic.protocol=http"

Sources

^[400-devops-03-containerization-traefik.md]

  • [[Docker]]
  • [[Reverse proxy]]
  • [[Load Balancer]]