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=webattaches the container to the specified network (in this example, thewebnetwork).^[400-devops-03-containerization-traefik.md] - Enable:
traefik.enable=trueactivates Traefik for the specific container.^[400-devops-03-containerization-traefik.md] - Frontend Rule:
traefik.basic.frontend.rule=Host:domain2.comdefines the routing rule, such as matching a specific domain name (e.g.,domain2.com).^[400-devops-03-containerization-traefik.md] - Port:
traefik.basic.port=8080specifies the internal port on the container that Traefik should forward traffic to.^[400-devops-03-containerization-traefik.md] - Protocol:
traefik.basic.protocol=httpsets 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]
Related¶
- [[Docker]]
- [[Reverse proxy]]
- [[Load Balancer]]