Traefik

Routing that follows your containers instead of a static config file.

2guides Feed

Traefik reads your container labels and builds its routing table from them. Start a container with the right labels and it is routable; stop it and the route disappears. There is no config file to edit and no reload to trigger.

The model has four pieces. An entrypoint is a port Traefik listens on. A router matches requests, usually by Host header. A service is where matched requests go. A middleware sits between them and does one thing — strip a prefix, add a header, enforce basic auth.

Reach for Traefik when containers are created and destroyed by something other than you: a deployment platform, a Compose file that changes often, a Swarm cluster. Reach for nginx when the topology is static and you would rather read one explicit file than reason about label precedence.

Two problems account for most of the trouble. The first is label placement: under Swarm, the provider reads labels from the service, so labels on the container are simply not seen, and you get a healthy application answering 404. The second is forwarded headers. Traefik strips X-Forwarded-Proto and X-Forwarded-For unless the request comes from an address in the entrypoint’s trustedIPs — which is the correct default, and which produces redirect loops and useless access logs when it is not configured.

There is a security note worth taking seriously. Traefik’s Docker provider needs the Docker socket, and read access to that socket exposes every container’s configuration and environment. On a shared or untrusted host, put a filtering socket proxy between them rather than mounting it directly.

Start here

How to Run Cloudflare Tunnel in Front of Traefik

Expose Docker services through Cloudflare with no inbound ports open — cloudflared plus Traefik, the forwarded-header setting that trips people up, and how to verify the firewall is closed.

Advanced · 4 min read

Beginner to advanced

A reading order that builds Traefik knowledge in the sequence it is actually needed.

  1. Build Zero-Downtime Deploys in Dokploy with Docker Health Checks 4 min
  2. Operate How to Run Cloudflare Tunnel in Front of Traefik 4 min

Common problems

Failure modes that come up repeatedly with Traefik, and where each one is solved.

A running container returns 404 from Traefik
With `exposedByDefault=false` the container needs `traefik.enable=true`, and the router needs an entrypoint label matching a defined entrypoint.
The application thinks every request is plain HTTP
Traefik discards X-Forwarded-* headers from untrusted sources. Add the upstream proxy's address to the entrypoint's trustedIPs list.
Labels are ignored on a Swarm service
Under Swarm the provider reads service labels. Move them from the container's `labels` to `deploy.labels`.

Latest Traefik guides

Browse the archive
  • advanced

    How to Run Cloudflare Tunnel in Front of Traefik

    Expose Docker services through Cloudflare with no inbound ports open — cloudflared plus Traefik, the forwarded-header setting that trips people up, and how to verify the firewall is closed.

    4 min

Frequently asked questions

Traefik or nginx for a container host?

Traefik when containers come and go and you want routing to follow them automatically. nginx when the topology is static and you would rather have one explicit config file to read.

Is mounting the Docker socket into Traefik safe?

It is a real trade-off. Read access to the socket exposes every container and its environment variables, and a read-only mount does not change that. On a host with untrusted workloads, put a socket proxy in front of it.

Do I need Traefik to handle TLS?

Not if something upstream already terminates it — a CDN, a tunnel or a load balancer. In that case a plain HTTP entrypoint keeps the configuration smaller and removes the ACME challenge problem entirely.

Sources

  1. Traefik documentation Traefik Labs Primary source
  2. Traefik Docker provider Traefik Labs Primary source
  3. Traefik entrypoints Traefik Labs Primary source