Route Docker containers with Traefik
Traefik receives requests at an EntryPoint, a Router selects them by rules, and a Service forwards them to a container. With the Docker provider enabled, Traefik can discover containers and their routing labels. This guide configures one local HTTP route with Docker Compose, then shows how to verify and troubleshoot it. TLS, Kubernetes, and production dashboard exposure are out of scope.
Traefik receives requests at an EntryPoint, a Router selects them by rules, and a Service forwards them to a container. With the Docker provider enabled, Traefik can discover containers and their routing labels. This guide configures one local HTTP route with Docker Compose, then shows how to verify and troubleshoot it. TLS, Kubernetes, and production dashboard exposure are out of scope.
Install configuration selects EntryPoints and providers when Traefik starts; provider supplied routing configuration defines Router and Service rules. This distinction separates listener and provider setup from request routing.
Minimal local setup
Prerequisites: Docker Engine and Docker Compose. The example follows the Traefik v3.7 quick start; whoami.localhost is for local testing. The Docker socket can grant powerful control over Docker, so restrict access.
services:
traefik:
image: traefik:v3.7
command:
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
whoami:
image: traefik/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"web listens on port 80. The label creates a Host rule; the Docker provider builds a Service target from the container. Choose and pin image versions suitable for your environment; this sample was not run.
Run docker compose up -d, check docker compose ps, then request curl -i http://whoami.localhost/. A whoami response verifies the rule and backend connection together. If it fails, inspect docker compose logs traefik whoami, the request Host, Docker discovery, and whether another process occupies port 80.
This exposes HTTP only. The official quick start enables an unauthenticated dashboard with --api.insecure=true; that is for development and must not be copied to production. HTTPS needs separate certificate and TLS resolver configuration. A single backend response does not establish high availability. Traefik's default HTTP load-balancing strategy is weighted round robin. Health checks can remove unhealthy servers, but the check path should reflect readiness to serve real traffic.
If the router exists but returns 502/504, check that Traefik and the app share a Docker network and that the app listens on the expected internal port. Specify traefik.http.services.whoami.loadbalancer.server.port when automatic port detection is not appropriate. In a disposable local setup, docker compose down stops and removes the sample resources; in production, restore the last approved configuration through the deployment process.
Sources read 2026-11-19: Docker quick start, configuration overview, EntryPoints, HTTP Services, and routing configuration providers. No deployment, runtime test, TLS setup, or failover test was performed.