DockerTraefik automatically detects your containers using labels. These labels allow you to:
- Tell Traefik that a container should be exposed to the web.
- Define routing rules (domain name, entrypoint, etc.)
For this step, we’ll use the Apache / PHP-FPM / MariaDB stack that we’ve already deployed.
The external network
In our configuration, Traefik is deployed in a separate stack. To make your application containers visible to Traefik:
- We create an external
proxy-traefiknetworkDocker (already done in the previous section). - Each application stack must join this external network.
Example for our PHP/Apache stack:
networks:
proxy-traefik:
external: trueCela permet à Traefik de communiquer avec les conteneurs sans que leurs ports internes soient exposés directement à Internet.Example labels for a web container
In the Apache or PHP-FPM service:
services:
web:
image: php:8.2-apache
container_name: monsite-web
restart: unless-stopped
networks:
- proxy-traefik
labels:
- "traefik.enable=true" # On active Traefik sur ce conteneur
- "traefik.http.routers.monsite.rule=Host(`monsite.local`)" # Domaine à router
- "traefik.http.routers.monsite.entrypoints=web" # Entrypoint défini dans Traefik
Here, Traefik automatically detects the container and knows it must route traffic to
monsite.local.
Labels are simple metadata used to “tag” the container for Traefik.
Simplified flow diagram
Internet
|
Traefik (stack séparé)
|
|-- proxy-traefik (réseau externe)
|
-------------------------------
| | |
Apache PHP-FPM MariaDB
(web) (backend) (bdd)
proxy-traefikThe web and backend containers are connected to the external network.- Traefik can thus route traffic to the correct container using the labels.
- The containers do not expose their ports directly to the Internet, which secures the stack.
💡 Tip:
- Labels do not modify the container; they are used solely to inform Traefik.
- You can add as many labels as needed to define more complex rules (HTTPS, redirects, middleware, etc.)