Every service you add to a homelab needs a front door, and the front door is where most self-hosted setups quietly go wrong. You end up with a hand-written nginx server block per app, a certbot cron job nobody remembers to renew, and a wall of config that has to be edited — and the proxy restarted — every single time you stand up something new. Add a fourth or fifth container and the proxy file becomes the thing you are afraid to touch. Traefik is built specifically to remove that tax: it reads your Docker containers, generates the routes itself, and reconfigures in real time without a restart.
Traefik is an open-source application proxy, and Docker is a first-class citizen for it — the project’s own Docker quick start describes native support for containers and services. You drop a couple of labels on a container, and Traefik notices, routes the domain to it, and requests a Let’s Encrypt certificate for it, all automatically. The current stable release is v3.7.19 (published 13 November 2026, per the project’s GitHub releases), and that is what this guide deploys. If you already run Caddy and like its config file, this is the complementary approach: Traefik pushes configuration into the proxy from your containers instead of pulling it out of a file you maintain by hand.
What Traefik actually does
Traefik sits on ports 80 and 443 and inspects every incoming request. Four concepts describe how it decides what to do, and they come straight from the project’s core documentation:
- Entrypoints are the network doors into Traefik — the port that receives packets and whether it speaks TCP or UDP. You will define
webon 80 andwebsecureon 443. - Routers match a request to the service that should handle it, based on a rule such as the
Hostheader or the URL path. - Services describe how to actually reach the backend — for Docker, the container’s internal address and port.
- Providers are where Traefik discovers routes. The Docker provider queries the Docker API and updates routes dynamically when a container starts or stops.
The part that matters day to day is the last one. Because the Docker provider polls the Docker socket, the proxy config lives next to the app it serves. Stand up a new container with labels, and the route appears without touching Traefik. Stop the container, and the route disappears. There is no single config file that becomes a merge conflict between ten different apps.
A production-shaped Docker Compose stack
The official quick start runs traefik:v3.7 with --api.insecure=true and the dashboard on port 8080, and it says plainly not to use that flag in production. The stack below is the production version of the same idea: two entrypoints, no unauthenticated dashboard, a real certificate resolver, and a dedicated Docker network so Traefik only sees containers you opt in.
Create a directory for Traefik’s state and a compose file:
mkdir -p ~/traefik && cd ~/traefik
touch acme.json && chmod 600 acme.json
acme.json is where Let’s Encrypt certificates are stored, and Traefik requires it to be mode 600 — an open file makes the client refuse to start. Now the stack itself:
services:
traefik:
image: traefik:v3.7
container_name: traefik
restart: unless-stopped
command:
- "--configFile=/etc/traefik/traefik.yml"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.yml:/etc/traefik/traefik.yml:ro
- ./acme.json:/acme.json
networks:
- proxy
networks:
proxy:
name: proxy
Three things are worth pausing on. The Docker socket is mounted read-only because Traefik only needs to read container metadata, and mounting the whole socket is itself a trust decision — anything that can talk to it can control Docker. The acme.json volume is not read-only because Traefik has to write renewed certificates into it. The proxy network is the boundary: a container is only routable if it joins this network.
Next to the compose file, add the static configuration:
entryPoints:
web:
address: ":80"
http:
redirections:
entryPoint:
to: websecure
scheme: https
permanent: true
websecure:
address: ":443"
http:
tls:
certResolver: letsencrypt
providers:
docker:
exposedByDefault: false
network: proxy
certificatesResolvers:
letsencrypt:
acme:
email: [email protected]
storage: /acme.json
httpChallenge:
entryPoint: web
The web entrypoint exists only to catch plaintext traffic and redirect it to HTTPS, using the entrypoints redirection option — the permanent: true flag makes it a 301. The websecure entrypoint turns on TLS and points at the resolver. Setting exposedByDefault: false is the single most important line in the file: it means a container is only exposed if you explicitly label it, so a stray database container never accidentally becomes internet-facing. Traefik’s default is true, which is convenient for a demo and uncomfortable in production.
Bring it up:
docker compose up -d
Exposing a service with labels
With Traefik running, exposing an app is a matter of adding labels and joining the proxy network. This is a minimal whoami service, the same sample app the official docs use:
services:
whoami:
image: traefik/whoami
container_name: whoami
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.example.com`)"
- "traefik.http.routers.whoami.entrypoints=websecure"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
networks:
proxy:
external: true
traefik.enable=true is required because we set exposedByDefault: false. The router rule says which hostname maps here, the entrypoint pins it to HTTPS, and the service label tells Traefik which internal container port to forward to — Traefik cannot always guess the port from a multi-port image, so naming it explicitly avoids surprises. Apply it with docker compose up -d in the app’s own directory. On the first request to that hostname, Traefik performs an ACME HTTP-01 challenge over the web entrypoint and stores the certificate in acme.json. After that the route is live on HTTPS with no manual cert step.
By default Traefik manages 90-day Let’s Encrypt certificates and starts renewing 30 days before expiry, so renewal is not something you schedule. One caveat the docs call out explicitly: Traefik does not check whether a certificate is still in use before renewing it, so old domains linger in acme.json rather than being pruned.
Middleware: the part nginx makes painful
A router can attach middlewares, which run in the request path before it reaches your app. Middlewares are where things like basic auth, rate limiting, HTTPS redirects, and header manipulation live, and in Traefik they are declared as labels too. A password-protected dashboard is the classic example:
services:
traefik:
image: traefik:v3.7
container_name: traefik
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.yml:/etc/traefik/traefik.yml:ro
- ./acme.json:/acme.json
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.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=dash-auth"
- "traefik.http.middlewares.dash-auth.basicauth.users=admin:$$apr1$$H6us4k9Z$$0e3Xk1Wq1Xk5Z8yZ8oQ8c/"
The dashboard is exposed through the internal api@internal service rather than a port, and the basicauth middleware gates it behind a user and an htpasswd hash. The doubled $$ is Compose escaping a single $ — a detail that trips up nearly everyone the first time. Because the dashboard is now behind a domain and a password, there is no need for the insecure flag the quick start warns against. A dashboard you can see is a dashboard you can actually use to debug routing, which is most of the value.
Traefik, Caddy, or nginx Proxy Manager?
These three occupy the same slot, and the honest answer is that they optimize for different things. Caddy’s strength is a tiny, human-readable config file and automatic HTTPS with almost no ceremony; it is the better fit when you maintain a small number of services by hand and want the config in one place. Traefik’s strength is that the config lives with the containers, which pays off once you have a rotating cast of apps, ephemeral preview environments, or a compose-heavy setup where standing something up should not involve editing a proxy file. nginx Proxy Manager is the point-and-click option, which is easier for a first proxy but gives you a GUI to maintain instead of code you can version and diff. If you want to go deeper on hardening the rest of the stack, the homelab security essentials guide pairs well with this one.
FAQ
Does Traefik need the Docker socket, and is that safe?
The Docker provider reads container metadata through the socket, so yes, it needs access. Mounting it read-only (:ro) limits what Traefik can do, though the socket still grants broad visibility into your Docker host. An alternative is a socket proxy such as Tecnativa/docker-socket-proxy that exposes only the specific API paths Traefik needs, at the cost of another moving part.
Why is acme.json mode 600 required?
It holds the private keys for your certificates. Traefik checks the permissions at startup and refuses to use the file if it is world-readable, because leaking it would let someone impersonate your domains.
What is the difference between static and dynamic configuration?
Static configuration — entrypoints, providers, certificate resolvers — is loaded once at startup from traefik.yml or CLI flags. Dynamic configuration — routers, services, middlewares — can change at runtime and, with the Docker provider, comes from container labels. The split is why adding an app never requires restarting Traefik.
Do I need exposedByDefault: false?
It is not required, but you want it. With the default of true, every container on the Docker provider’s network gets a router, and a service you did not intend to publish can end up reachable if it has a web port. Explicit labeling is a small price for knowing exactly what is exposed.
Does this work with Docker Compose across separate compose files?
Yes, and that is the normal pattern. Declare the proxy network as external: true in each app’s compose file and attach the app to it. Traefik sees any container on that network and routes based on its labels, regardless of which compose file started it.