because I'm struggling to have the real IP forwarded to the docker apps, I'm now running docker traefik in host network mode.
traefik and services work. Here is my configuration
docker-compose.yaml:
---
services:
traefik:
image: traefik:latest
container_name: traefik
network_mode: host
volumes:
- ./traefik.yaml:/traefik.yaml
- ./letsencrypt/:/letsencrypt/
- /run/docker.sock:/var/run/docker.sock:ro
labels:
- traefik.enable=true
- traefik.http.routers.traefik.rule=Host(`frontal.cestpasla.norhere.net`)
- traefik.http.routers.traefik.entrypoints=websecure
- traefik.http.routers.traefik.service=api@internal
- traefik.http.services.traefik-0000traefik.loadbalancer.server.port=8080
- traefik.http.routers.traefik.tls.certresolver=myresolver
- traefik.http.routers.traefik.middlewares=traefik-auth
- traefik.http.middlewares.traefik-auth.basicauth.users=me:encryptedpassword
The static traefik yaml file:
---
api:
dashboard:
providers:
docker:
exposedByDefault: false
entrypoints:
web:
address: 10.20.0.2:80
websecure:
address: 10.20.0.2:443
certificatesresolvers:
myresolver:
acme:
tlschallenge: true
email: [email protected]
storage: /letsencrypt/acme.json
#log:
# level: DEBUG
The line that is problematic is:
- traefik.http.services.traefik-0000traefik.loadbalancer.server.port=8080
The dashboard service name is traefik-0000traefik
, probably because the docker-compose file is in a folder named 0000.traefik
. I don't remember at which point in my tests I suddenly had to add this line, but as of now, in network host mode, if I don't use this line, I can see this error in docker logs:
2025-03-12T11:25:38Z ERR error="service \"traefik-0000traefik\" error: port is missing" container=traefik-0000traefik-09ccfe569180f81f22b135fd75082ed017ce95a7dc0ade1ab5a7e2bfbd960886 providerName=docker
The question :
If I must use a config line for the dashboard service, can I at least choose the service name, say traefik_dashboard
or similar ? and How ?
This happens to be a known “problem” and there is this exact question on traefik forum. For a reason I don't really understand yet, this seems to be normal. I quote :
The solution is to add a label in the traefik service definition, which I did. but I thought I had to use the same name as the one that appears int the error log message. However, that name was just autogenerated, because there was no name in my config. But one can use any name they want in the label. The name does not matter, there just must be one. So I just could write this: