Deploy Traefik as a Dynamic Cloud‑Native Reverse Proxy with Docker
This guide explains what Traefik is, highlights its automatic service‑discovery and dynamic routing features, and provides step‑by‑step Docker‑Compose instructions to install Traefik, deploy a sample service, and verify the setup using curl or a browser.
What is Traefik
Traefik is a modern HTTP reverse proxy and load balancer designed for micro‑service deployments. It receives external requests and routes them to the appropriate backend services automatically.
Key Advantages
Traditional reverse proxies require manual route configuration, which is error‑prone in dynamic environments. Traefik watches service registries or orchestrator APIs and generates routes in real time, removing the need for manual updates.
Core components:
Client requests
Entry points
Routers (matching rules)
Middlewares (modify requests)
Services (backend applications)
Installation
Create a docker-compose.yml file with the following content:
services:
traefik:
image: traefik:v3.6
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sockStart Traefik:
docker-compose up -dDeploy the First Service
Deploy a simple whoami service to test routing. Create a whoami.yml file:
services:
whoami:
image: traefik/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"Launch the service:
docker-compose -f whoami.yml up -dTesting the Setup
Option 1: curl http://whoami.localhost Option 2: Open a browser and navigate to http://whoami.localhost. Expected response includes hostname, IP addresses and forwarded headers, e.g.:
Hostname: 068c0a29a8b7
IP: 127.0.0.1
IP: ::1
IP: 192.168.147.3
RemoteAddr: 192.168.147.2:56006
GET / HTTP/1.1
Host: whoami.localhost
User-Agent: curl/8.7.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 192.168.147.1
X-Forwarded-Host: whoami.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 9232cdd4fd6c
X-Real-Ip: 192.168.147.1Highlighted Features
Automatic service discovery – new containers are detected without restarting Traefik.
Dynamic configuration – routes are updated in real time.
Docker integration – native support via Docker labels.
Dashboard – visual interface for managing routes.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
