What this lab does

Traefik with Docker solves a concrete problem: exposing several containers on port 80 without reserving a separate port for each one. In this lab you install Traefik as a reverse proxy with its Docker provider, bring up two backends with routing labels, and use curl to prove each hostname reaches the right container.

Labels instead of configuration files

Everything is declared in a single compose.yaml, the approach recommended by the official Docker Compose documentation: Traefik mounts the Docker socket read-only, listens on port 80, and exposes its API on port 8080. Each backend adds traefik.http.routers.<name>.rule=Host(`domain`), and Traefik recomputes its routes the moment it spots the container, with nothing to restart. We covered the same per-container networking pattern in our Docker networking guide: bridge, host, and custom networks.

How it fits with the rest of the stack

If you’re used to managing certificates and domains by hand, compare this declarative approach with our guide to installing Nginx Proxy Manager with Docker, which solves the same problem from a web UI. To keep an eye on the containers Traefik will route to, our Portainer with Docker Compose lab is a good companion. Traefik’s source is public on its GitHub repository. Find more self-hosting guides under the Tools category and the rest of our reproducible walkthroughs in the hands-on labs.

FAQ

What is Traefik?

Traefik is a reverse proxy and load balancer built for container environments. Instead of maintaining a routes file by hand, it watches the Docker socket and builds its configuration dynamically from the labels you attach to each container.

How does Traefik know which container to send a request to?

Each container carries a traefik.http.routers.<name>.rule label with a condition, usually Host(`domain`). When a request arrives, Traefik matches the Host header against those rules and forwards the traffic to the container whose rule matches.

Is it safe to use –api.insecure=true in production?

No. That flag exposes Traefik's dashboard and API without authentication, which is only acceptable for local testing like this lab. In production it should sit behind authentication and, typically, the API port should not be published externally.

How is Traefik different from Nginx Proxy Manager?

Nginx Proxy Manager is managed mostly through its web UI, adding each domain by hand. Traefik is configured declaratively with labels on each container, so a new service is routed the moment it starts, without opening any admin panel.