Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
Entrypoints are the ports (80, 443). Routers match requests (Host(...), PathPrefix(...)) and send them to services (your containers). Middlewares change requests on the way (redirects, auth, headers, rate limits). Providers (Docker, Kubernetes, files) tell Traefik what exists. Static config (entrypoints, providers, ACME) is read at start; dynamic config (routers, services, middlewares) changes live.
| Item | Value |
|---|---|
| Image / binary | traefik:v3.5 (Docker) or the release file from github.com/traefik/traefik/releases |
| Static config | flags, or /etc/traefik/traefik.yml |
| Dynamic config | Docker labels, Kubernetes objects, or files in /etc/traefik/dynamic/ |
| Certificates | acme.json (holds private keys — mode 600) |
| Ports | 80, 443 (and 8080 for the dashboard only if you enable the insecure API — do not) |
Run Traefik with Docker Compose (RHEL and Ubuntu)
Install Docker Engine first (see the Docker guide). Make a network for the proxy and a folder:
docker network create proxy
mkdir -p ~/traefik/letsencrypt && cd ~/traefik
touch letsencrypt/acme.json && chmod 600 letsencrypt/acme.jsonservices:
traefik:
image: traefik:v3.5
restart: unless-stopped
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=proxy
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --certificatesresolvers.le.acme.email=ops@example.com
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
- --api.dashboard=true
- --log.level=INFO
- --accesslog=true
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./letsencrypt:/letsencrypt
networks: [proxy]
labels:
- traefik.enable=true
- traefik.http.routers.dashboard.rule=Host(`traefik.example.com`)
- traefik.http.routers.dashboard.entrypoints=websecure
- traefik.http.routers.dashboard.tls.certresolver=le
- traefik.http.routers.dashboard.service=api@internal
- traefik.http.routers.dashboard.middlewares=dash-auth
- traefik.http.middlewares.dash-auth.basicauth.users=admin:$$2y$$12$$Zq…
networks:
proxy:
external: trueMake the password hash with htpasswd -nBC 12 admin and write every $ as $$ in the Compose file.
| Setting | Why |
|---|---|
exposedbydefault=false | Only containers with traefik.enable=true are published — nothing by accident. |
Redirect web → websecure | HTTP always goes to HTTPS. |
certificatesresolvers.le… | Automatic Let's Encrypt certificates (HTTP-01 on port 80). |
docker.sock:ro | Traefik reads container labels; read-only (see "Make it safe"). |
| Dashboard on its own HTTPS host with basic auth | Never the insecure :8080 dashboard. |
Test against Let's Encrypt staging first: add --certificatesresolvers.le.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory, then remove it and empty acme.json.
Publish an app with labels
services:
shop:
image: registry.example.com/shop:1.4.0
restart: unless-stopped
networks: [proxy]
labels:
- traefik.enable=true
- traefik.http.routers.shop.rule=Host(`shop.example.com`)
- traefik.http.routers.shop.entrypoints=websecure
- traefik.http.routers.shop.tls.certresolver=le
- traefik.http.services.shop.loadbalancer.server.port=3000
- traefik.http.routers.shop.middlewares=sec-headers
- traefik.http.middlewares.sec-headers.headers.stsSeconds=31536000
- traefik.http.middlewares.sec-headers.headers.contentTypeNosniff=true
- traefik.http.middlewares.sec-headers.headers.frameDeny=true
networks:
proxy:
external: truecd ~/shop && docker compose up -d
curl -I https://shop.example.com
HTTP/2 200
strict-transport-security: max-age=31536000No proxy config to edit — Traefik saw the new container and its labels. The app does not publish ports itself; only Traefik is public.
Without Docker: binary + systemd
For servers without containers, run the binary with a static file and a dynamic folder:
entryPoints:
web:
address: ":80"
http:
redirections:
entryPoint: { to: websecure, scheme: https }
websecure:
address: ":443"
providers:
file:
directory: /etc/traefik/dynamic
watch: true
certificatesResolvers:
le:
acme:
email: ops@example.com
storage: /var/lib/traefik/acme.json
httpChallenge: { entryPoint: web }http:
routers:
shop:
rule: "Host(`shop.example.com`)"
entryPoints: [websecure]
service: shop
tls: { certResolver: le }
services:
shop:
loadBalancer:
servers:
- url: "http://10.0.1.11:3000"
- url: "http://10.0.1.12:3000"Run it with a systemd unit (ExecStart=/usr/local/bin/traefik --configFile=/etc/traefik/traefik.yml, a traefik user and AmbientCapabilities=CAP_NET_BIND_SERVICE for ports 80/443).
In Kubernetes
Traefik is the default ingress of k3s. Elsewhere install the Helm chart (helm repo add traefik https://traefik.github.io/charts, chart traefik/traefik). It reads normal Ingress objects and its own IngressRoute CRD:
Daily use: the commands and the real uses
docker compose -f ~/traefik/compose.yaml logs -f traefik
docker compose -f ~/traefik/compose.yaml pull && docker compose -f ~/traefik/compose.yaml up -d
docker inspect shop-shop-1 --format '{{json .Config.Labels}}' | jq .
curl -sI https://shop.example.com | head -3Open the dashboard (https://traefik.example.com) to see every router, service and middleware, with errors in red.
Real uses at work:
- One server with many Docker Compose apps, each with its own domain and automatic HTTPS.
- Kubernetes ingress (k3s), canary releases with weighted services.
- Middlewares for SSO (forward auth), IP allow lists, rate limits and headers.
Make it safe
Security checklist:
- Access to
docker.sock= root on the host. Mount it read-only, or better use a socket proxy (only the API calls Traefik needs). exposedbydefault=false; publish only labelled containers.- Dashboard behind HTTPS + auth (or not exposed at all); never
--api.insecure=trueon a server. acme.jsonmode600and in backups — it holds all private keys.- Security-header and rate-limit middlewares; pin the image version (
traefik:v3.5) and update on purpose.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
404 page not found | No router matched: label missing (traefik.enable=true), wrong Host, or wrong entrypoint. | Dashboard → HTTP routers; check the labels with docker inspect. |
Bad Gateway (502) | Wrong app port or the containers are not on the same network. | loadbalancer.server.port; both on the proxy network (providers.docker.network). |
Browser shows TRAEFIK DEFAULT CERT | ACME failed. | docker compose logs traefik; port 80 open; DNS points here; acme.json mode 600. |
permissions 644 for /letsencrypt/acme.json are too open | Mode not 600. | chmod 600 letsencrypt/acme.json. |
| Dashboard 404 | No router to api@internal, or api.dashboard off. | Use the dashboard labels above. |
Error while parsing rule Host(...) | Wrong quotes around the host name. | Put the host name between backticks inside Host(…), as in the labels above. |
Compose: $2y…: variable is not set | $ in the bcrypt hash. | Write every $ as $$. |
Next steps
- Quick how-tos: Expose an app with an Ingress and TLS, Route containers with labels.
- Command page: traefik.
- At work: The cloud-native proxy, The proxy that reads Docker and Kubernetes.
- What runs under it: Docker Engine, k3s. The classic proxies: Nginx, HAProxy.
- Practise: Lab: web, proxy and TLS.
1Why set exposedbydefault=false?
Then only containers with traefik.enable=true are published, so nothing is exposed by accident.
2The browser shows "TRAEFIK DEFAULT CERT". What does it mean?
Getting the Let's Encrypt certificate failed; read the Traefik log (port 80, DNS, acme.json rights).