LIVEReading: Run Traefik: Auto-Routing Proxy for Docker AppsTotal time: 10 minSteps: 7Worked first time: 72% LIVEReading: Run Traefik: Auto-Routing Proxy for Docker AppsTotal time: 10 minSteps: 7Worked first time: 72%
CBW
Run Traefik: Auto-Routing Proxy for Docker Apps
Mediumgithub.com/traefik/traefik2026-06-14

Run Traefik: Auto-Routing Proxy for Docker Apps

Traefik sits in front of your Docker containers and automatically creates routes to each one — no manual config per service. This guide gets it running locally in under 10 minutes.

// Build stats

  • Total time10 min
  • Number of steps7
  • DifficultyMedium
  • Worked first time72%
// Before you start

What you need

  • Docker Desktop installed and running
  • A terminal (Mac: Terminal, Windows: PowerShell or WSL, Linux: any shell)
  • Port 80 and 8080 free on your machine
  • No coding skill needed
01
Step 1 of 7

Create a dedicated Docker network

1 min

Traefik needs to talk to your other containers. Docker networks are isolated lanes of communication. Creating one called 'web' lets Traefik see any container you later attach to it.

Terminal · mac
$ docker network create web
What you should see
A long hex string like: a3f2c1d4e5b6... (the network ID). No error means success.
This might happen

Error: network with name web already exists

That's fine — the network is already there. Move on to step 2.

02
Step 2 of 7

Create the Traefik config file

2 min

Traefik needs a small config file to know it should watch Docker and where to show its dashboard. Run this block exactly as written — it creates a file called traefik.toml in your current folder. The three lines inside tell Traefik: expose the API, watch Docker, and don't require HTTPS yet.

Terminal · mac
$ cat > traefik.toml << 'EOF'
$ [api]
$ insecure = true
$
$ [providers.docker]
$ network = "web"
$ EOF
What you should see
No output. Run 'ls' and you should see traefik.toml listed.
This might happen

On Windows PowerShell the heredoc syntax above may fail

Open Notepad, paste the three lines between the EOF markers, and save the file as traefik.toml in your current folder. Then continue.

03
Step 3 of 7

Start Traefik with Docker

2 min

This command pulls the official Traefik image and starts it. It maps port 80 (web traffic) and port 8080 (the dashboard) from your machine into the container. It also mounts the config file you just made and gives Traefik read access to Docker so it can watch for new containers.

Terminal · mac
$ docker run -d \
$ --name traefik \
$ --network web \
$ -p 80:80 \
$ -p 8080:8080 \
$ -v $PWD/traefik.toml:/etc/traefik/traefik.toml \
$ -v /var/run/docker.sock:/var/run/docker.sock \
$ traefik:v3.0
What you should see
A long container ID printed on one line. Run 'docker ps' and you should see a container named 'traefik' with status 'Up'.
This might happen

Port 80 or 8080 already in use — container exits immediately

Stop whatever is using those ports (common culprits: Apache, nginx, another app). On Mac/Linux run: sudo lsof -i :80 to find it.

04
Step 4 of 7

Open the Traefik dashboard

1 min

Traefik ships with a built-in web UI that shows every route it knows about. Open your browser and go to the address below. You should see the Traefik dashboard with no routes yet — that is expected.

Terminal · mac
$ open http://localhost:8080/dashboard/
What you should see
A browser tab opens showing the Traefik dashboard with sections for HTTP, TCP, and UDP routers. All counts will be low or zero — that is correct at this stage.
This might happen

'open' command not found (Linux or Windows)

Just type http://localhost:8080/dashboard/ directly into your browser address bar.

05
Step 5 of 7

Launch a sample app and let Traefik route to it

2 min

This starts a tiny demo web app (whoami) and adds Docker labels that Traefik reads automatically. The label 'traefik.http.routers.whoami.rule' tells Traefik: send any request with the Host header 'whoami.localhost' to this container. No config file editing needed — Traefik picks it up live.

Terminal · mac
$ docker run -d \
$ --name whoami \
$ --network web \
$ --label "traefik.enable=true" \
$ --label "traefik.http.routers.whoami.rule=Host(\`whoami.localhost\`)" \
$ traefik/whoami
What you should see
A container ID. Run 'docker ps' and you should now see both 'traefik' and 'whoami' running.
This might happen

curl to whoami.localhost returns 'connection refused' or 404

Wait 5 seconds and try again — Traefik needs a moment to detect the new container. Also confirm both containers are on the 'web' network with: docker inspect whoami | grep web

06
Step 6 of 7

Test that Traefik is routing correctly

1 min

This curl command sends a request to port 80 on your machine but tells the server the hostname is 'whoami.localhost'. Traefik reads that hostname, matches the rule you set in step 5, and forwards the request to the whoami container. You should see the container's IP, hostname, and request headers printed back.

Terminal · mac
$ curl -H "Host: whoami.localhost" http://localhost
What you should see
Several lines starting with: Hostname: <container-id>, IP: 172.x.x.x, and a list of request headers. This confirms Traefik routed the request successfully.
This might happen

curl: command not found on Windows

Use PowerShell instead: Invoke-WebRequest -Uri http://localhost -Headers @{Host='whoami.localhost'} | Select-Object -ExpandProperty Content

07
Step 7 of 7

Clean up when you are done

1 min

These commands stop and remove the two containers and the network you created. Your machine goes back to its original state. The traefik.toml file stays in your folder — delete it manually if you want.

Terminal · mac
$ docker stop whoami traefik && docker rm whoami traefik && docker network rm web
What you should see
Four lines: whoami, traefik, whoami, traefik — each confirming the stop and removal. Then the network ID on the last line.
// Status

cooked. baked. worked.

A running Traefik instance on your machine with a live dashboard at localhost:8080, automatically routing web traffic to Docker containers based on labels — no manual route config required.

// the honest bit

The honest part

This guide runs Traefik in insecure/local mode — fine for learning but not safe to expose to the internet as-is. For real production use you need HTTPS (Let's Encrypt config), proper firewall rules, and ideally Kubernetes or Docker Swarm. The dashboard has no password in this setup; anyone on your network can see it. Traefik's full power (Kubernetes Ingress, automatic TLS, middleware) requires significantly more configuration than shown here.