Traefik automatically detects services from Docker and Kubernetes without manual configuration. Just add Docker labels or Kubernetes IngressRoute and Traefik immediately starts routing traffic. Automatic SSL certificates via Let’s Encrypt, a built-in dashboard, and a rich middleware ecosystem make Traefik the ideal reverse proxy for cloud-native environments.
Why Traefik¶
- Auto-discovery — new containers are automatically registered from Docker, Kubernetes, or Consul
- Automatic SSL — Let’s Encrypt integration with HTTP-01 and DNS-01 challenge
- Dashboard — visual overview of routers, services, and middleware
- Middleware — authentication, rate limiting, redirect, strip prefix, headers, and more
Unlike Nginx or HAProxy, you do not need to restart the proxy when adding a new service. Traefik watches for changes in real time and dynamically updates configuration.
Docker setup¶
services:
traefik:
image: traefik:v3.0
command:
- --providers.docker=true
- --entrypoints.web.address=:80
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
ports: ['80:80', '443:443']
volumes: ['/var/run/docker.sock:/var/run/docker.sock:ro']
webapp:
image: myapp
labels:
- traefik.http.routers.webapp.rule=Host(`app.example.com`)
- traefik.http.routers.webapp.tls.certresolver=le
Configuration happens through Docker labels directly in docker-compose — no extra configuration files. Traefik reads the labels, creates a router, assigns a service, and automatically provisions an SSL certificate.
Middleware¶
labels:
- traefik.http.middlewares.rl.ratelimit.average=100
- traefik.http.middlewares.auth.basicauth.users=admin:$$apr1...
- traefik.http.routers.webapp.middlewares=rl,auth
Middleware is chained — you can apply rate limiting, authentication, CORS headers, and redirects to a single router simultaneously. For Kubernetes, Traefik supports IngressRoute CRD with even greater flexibility.
Traefik for Docker/K8s¶
Auto-discovery + automatic SSL = ideal for cloud-native environments. For static servers, Nginx remains the better choice due to lower overhead and a mature ecosystem.