DEV Community

Cover image for Traefik vs Caddy on a Docker VPS: which reverse proxy to choose
Fernando Chagas for Nuvits

Posted on Originally published at nuvits.net

Traefik vs Caddy on a Docker VPS: which reverse proxy to choose

To put a few services behind HTTPS on a Docker VPS, Caddy does it in three lines per domain and never touches the Docker socket. Traefik pays off when containers come and go often: it reads the labels on each one and adds the route by itself, with no reload. This comparison puts the same service behind Caddy 2.11.9 and Traefik v3.8.0 and shows what changes in configuration, HTTPS, security and resource use. Everything was tested on 1 December 2026 on a clean Ubuntu 24.04.5 LTS with Docker Engine 29.10.1 and Compose v5.8.1.

Comparison of Caddy 2.11.9 and Traefik v3.8.0 on a Docker VPS: with Caddy the route lives in the Caddyfile, a new service needs caddy reload, the Docker socket is not used and memory at rest was about 14 MiB; with Traefik the route lives in container labels, a new service is picked up automatically, the Docker socket is required and memory at rest was about 23 MiB

Quick comparison

Criterion Caddy 2.11.9 Traefik v3.8.0
Where the route is In the Caddyfile, one block per domain In labels on each service's container
New service Edit the Caddyfile and run caddy reload docker compose up -d; the route appears by itself
Docker socket Not used Needed to read the labels
Automatic HTTPS On by default Needs a certresolver with an email and acme.json
HTTP to HTTPS Automatic (308 in the test) Two flags (301 on GET, 308 on other methods)
HTTP/3 On by default One more flag and port 443/udp
Dashboard None; admin API on localhost:2019 Web dashboard, off by default
Memory at rest About 14 MiB About 23 MiB
Image (amd64) 93.5 MB 295 MB

Memory is each proxy at rest with two services behind it, and should be read as an order of magnitude. Neither one affects which plan you pick: the size of the VPS depends on your applications.

What you need

The example service is traefik/whoami v1.12.0, which returns the headers of the request it received. Run one proxy at a time: both want ports 80 and 443.

The same service behind Caddy

mkdir -p ~/caddy/conf && cd ~/caddy
Enter fullscreen mode Exit fullscreen mode
APP_DOMAIN=app.example.com
Enter fullscreen mode Exit fullscreen mode
{$APP_DOMAIN} {
    reverse_proxy whoami:80
}
Enter fullscreen mode Exit fullscreen mode
services:
  caddy:
    image: caddy:2.11.9
    restart: unless-stopped
    env_file: .env
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./conf:/etc/caddy:ro
      - caddy_data:/data
      - caddy_config:/config

  whoami:
    image: traefik/whoami:v1.12.0
    restart: unless-stopped

volumes:
  caddy_data:
  caddy_config:
Enter fullscreen mode Exit fullscreen mode

Validate, start and test:

docker compose config -q
docker run --rm --env-file .env -v "$PWD/conf:/etc/caddy:ro" caddy:2.11.9 caddy validate --config /etc/caddy/Caddyfile
docker compose up -d
curl -I http://app.example.com
curl https://app.example.com
Enter fullscreen mode Exit fullscreen mode

caddy validate ends with Valid configuration. In the test, HTTP answered 308 to https:// and HTTPS returned the whoami response with X-Forwarded-For filled in. Caddy requests the certificate, renews it and redirects without a single extra line.

The Compose file mounts the conf folder, not the file. The official image page warns against mounting the Caddyfile directly. In the test with the file mounted, a sed -i replaced the file on disk, the container kept reading the old one and caddy reload did not apply the change. With the folder mounted, the same edit went in on the next reload.

The same service behind Traefik

mkdir -p ~/traefik && cd ~/traefik
Enter fullscreen mode Exit fullscreen mode
APP_DOMAIN=app.example.com
ACME_EMAIL=you@example.com
Enter fullscreen mode Exit fullscreen mode
services:
  traefik:
    image: traefik:v3.8.0
    restart: unless-stopped
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --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=${ACME_EMAIL}
      - --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
      - --certificatesresolvers.le.acme.tlschallenge=true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - letsencrypt:/letsencrypt

  whoami:
    image: traefik/whoami:v1.12.0
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`${APP_DOMAIN}`)
      - traefik.http.routers.whoami.entrypoints=websecure
      - traefik.http.routers.whoami.tls.certresolver=le

volumes:
  letsencrypt:
Enter fullscreen mode Exit fullscreen mode
docker compose config -q
docker compose up -d
docker compose logs traefik
curl -I http://app.example.com
curl https://app.example.com
Enter fullscreen mode Exit fullscreen mode

In the test, curl -I got a 308 to https:// (a plain GET gets 301) and HTTPS returned the whoami response. The flags under command are the static configuration: entry points, the redirect and the certificate resolver. Changing one of them recreates the Traefik container. Labels are the dynamic configuration and apply as soon as the service's container starts.

Replace ACME_EMAIL with an address of your own. With an example.com address, Let's Encrypt refused the account and the Traefik log showed contact email has forbidden domain "example.com".

Keep exposedbydefault=false. Without that flag, Traefik creates a route for every container it can see. In the test, a container with no labels at all got a route under its own name, interno-exposto (Compose service and project), and answered 200 to curl -H 'Host: interno-exposto' http://IP:443/. With the flag, the same request returned 404.

Adding a second service

This is where the two differ most. With Traefik, the route travels with the service. Add this to docker-compose.yml, under services:

  api:
    image: traefik/whoami:v1.12.0
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - traefik.http.routers.api.rule=Host(`api.example.com`)
      - traefik.http.routers.api.entrypoints=websecure
      - traefik.http.routers.api.tls.certresolver=le
Enter fullscreen mode Exit fullscreen mode
docker compose up -d
curl https://api.example.com
Enter fullscreen mode Exit fullscreen mode

In the test, up -d created only the new container, the Traefik container kept the same start time and the domain answered 200 right after.

With Caddy there are two files. The service goes into docker-compose.yml, with no labels:

  api:
    image: traefik/whoami:v1.12.0
    restart: unless-stopped
Enter fullscreen mode Exit fullscreen mode

And the domain goes at the end of conf/Caddyfile:

api.example.com {
    reverse_proxy api:80
}
Enter fullscreen mode Exit fullscreen mode
docker compose up -d
docker compose exec -w /etc/caddy caddy caddy reload
curl https://api.example.com
Enter fullscreen mode Exit fullscreen mode

Before the reload, the new domain did not even complete the TLS handshake. After it, the domain answered 200 and the Caddy container did not restart. A typo does not take anything down either: with an unclosed block in the file, the reload answered syntax error: unexpected token '{', expecting '}' and the site already online kept returning 200.

Security: the Docker socket

Traefik only discovers containers because it reads the Docker socket. Its documentation warns that if Traefik is attacked, the attacker might get access to the host, and the Docker documentation says only trusted users should be allowed to control the daemon.

The :ro on the volume does not change that. It protects the socket file, but the API still accepts any command. In the test, a container with the socket mounted read-only stopped another one:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro docker:29.10.1-cli docker stop traefik-api-1
Enter fullscreen mode Exit fullscreen mode

docker compose up -d brings the service back.

To reduce the risk, the Traefik documentation suggests putting a filter between Traefik and the socket, such as docker-socket-proxy, which can allow read access to containers only.

The Caddy in this guide never touches the socket. What it has is an admin API on localhost:2019, inside the container. In the test it answered on 127.0.0.1:2019 through docker compose exec and refused the connection from outside, because the port is not published. If you want labels with Caddy, there is caddy-docker-proxy, which needs the socket again.

HTTPS and HTTP/3

With Caddy, every domain in the Caddyfile gets a certificate. It tries Let's Encrypt and, if that fails, ZeroSSL, with no configuration. The certificates live in the caddy_data volume.

With Traefik, each router needs the tls.certresolver=le label, and the certificates live in acme.json in the letsencrypt volume. Until the certificate is issued, Traefik serves the self-signed TRAEFIK DEFAULT CERT and the browser shows a security warning. If that happens, the reason is in docker compose logs traefik.

Caddy advertises HTTP/3 from the first response (alt-svc: h3=":443"), as long as 443/udp is published. With Traefik, the same header only showed up after adding --entrypoints.websecure.http3=true to command and "443:443/udp" to ports.

When to choose each one

Stay with Caddy if the VPS runs a few services that rarely change. The configuration is short, HTTPS needs nothing and no container exposed to the internet can see the Docker socket.

Go with Traefik if containers start and stop often, if deploys are automated or if each project has to carry its own route in its Compose file. In exchange for not touching the proxy on every new service, you accept more configuration and the care the socket requires.

With a panel, the choice is already made. Coolify uses Traefik by default and accepts Caddy as an alternative, and Dokploy uses Traefik. The comparison Coolify vs Dokploy covers that decision.

What was left out of the test

The test ran on a virtual machine with no public IP. Real DNS and the Let's Encrypt certificate were left out for both: Caddy used its internal certificate authority, with the same Caddyfile, and Traefik stayed on the default certificate. For HTTP/3, only the alt-svc header was checked, with no real QUIC connection. The Traefik dashboard, docker-socket-proxy, caddy-docker-proxy and performance under load were not tested either. Memory was measured on a second virtual machine, arm64, with the same files.

Next steps


Originally published at https://nuvits.net/en/blog/traefik-vs-caddy-docker-vps

Top comments (0)