Plain Traefik: Cutting the Reverse-Proxy Complexity

Why I ripped out the fancy ingress stack and went back to labels.

Plain Traefik: Cutting the Reverse-Proxy Complexity

I replaced tunnels plus an extra proxy with plain Traefik. Now I look in one place to see how traffic reaches a service. For a few dozen services on one box, that is the sweet spot.

The five labels

This is the whole routing config for one container:

traefik.enable=true
traefik.http.routers.myapp.rule=Host(`app.example.com`)
traefik.http.routers.myapp.entrypoints=websecure
traefik.http.routers.myapp.tls.certresolver=le
traefik.http.services.myapp.loadbalancer.server.port=3000

All five are valid in Traefik v3. One condition applies to the fourth. tls.certresolver=le works only if a resolver named le exists in the static config. The earlier post on the VPS migration shows that block.

Two defaults to change

exposedByDefault defaults to true. Traefik then routes every container it can see, including ones you never meant to publish. Set this in the static config:

--providers.docker.exposedbydefault=false

Only containers with traefik.enable=true get routes after that.

providers.docker.network picks the network Traefik uses to reach containers. A traefik.docker.network label on one container overrides it. If a service has several networks and traffic times out, check this first.

Turn the dashboard off with --api.dashboard=false.

The Docker socket

Traefik reads container labels through the Docker socket. Traefik’s own docs say “Accessing the Docker API without any restriction is a security concern”. They add that an attacker who compromises Traefik might get access to the underlying host.

A :ro mount on docker.sock does not make this safe. The flag covers the file, not the API, so every API call still works through a read-only mount.

The fix is a socket proxy. tecnativa/docker-socket-proxy with POST=0, on an internal network, lets Traefik read container data and nothing else. Traefik then talks to the proxy over TCP and never touches the socket.

A sketch:

services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy
    environment:
      POST: 0
      CONTAINERS: 1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks: [proxy-internal]

I listed only CONTAINERS. Your Traefik version may need more endpoints enabled, so check the socket proxy’s README.

Why one proxy

With tunnels plus a proxy, a request passed through two systems. When something broke, I had two places to read. Plain Traefik leaves one set of labels per service and one log. The cost is that Traefik is exposed directly, so the hardening layers in the VPS post matter more.

Adding a service

  1. Add the five labels to the container.
  2. Put the container on the network Traefik uses.
  3. Start it.
  4. Open https://app.example.com and check the certificate.

Step 4 depends on DNS pointing at the box.

Subscribe to Just another Geek

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe