Skip to content

Docker label configuration

Docker labels are metadata key-value pairs attached to Docker objects, such as containers or services.^[Traefik.md] While they serve a general purpose of organizing and managing container metadata, they are heavily utilized by tools like Traefik to configure routing and service discovery dynamically.^[Traefik.md]

Traefik configuration

When using Traefik as a reverse proxy, labels are placed within the docker-compose.yml file to define how the proxy handles the container.^[Traefik.md] The labels section in the YAML file accepts a list of strings formatted as "key=value".^[Traefik.md]

Common configuration keys include:

  • Network attachment: "[Traefik](<./traefik.md>).docker.network=web" specifies which Docker network Traefik should use to connect to the container.^[Traefik.md]
  • Enablement: "[Traefik](<./traefik.md>).enable=true" activates Traefik for the specific container.^[Traefik.md]
  • Frontend rules: "[Traefik](<./traefik.md>).basic.frontend.rule=Host:domain2.com" defines the routing condition (e.g., which domain name routes to this container).^[Traefik.md]
  • Port targeting: "[Traefik](<./traefik.md>).basic.port=8080" indicates the internal port on the container that Traefik should forward traffic to.^[Traefik.md]
  • Protocol: "[Traefik](<./traefik.md>).basic.protocol=http" sets the protocol to use for communication.^[Traefik.md]

Example

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"
^[Traefik.md]

  • [[Docker]]
  • Traefik
  • [[Reverse Proxy]]

Sources

^[Traefik.md]