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

Source: [https://nuvits.net/en/blog/traefik-vs-caddy-docker-vps](https://nuvits.net/en/blog/traefik-vs-caddy-docker-vps)

Published 2026-12-01, by Fernando Chagas.

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](https://nuvits.net/blog/traefik-vs-caddy-docker-vps/traefik-vs-caddy-comparison.webp)

## 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

- A VPS with Ubuntu 24.04, Docker Engine and the Compose plugin, installed as in [How to install Docker and Docker Compose on Ubuntu 24.04](https://nuvits.net/en/blog/install-docker-compose-ubuntu-24-04). The examples use the `deploy` user, a member of the `docker` group.
- Two DNS `A` records pointing to the VPS IP. The examples use `app.example.com` and `api.example.com`.
- Ports 80 and 443 free, plus 443/udp for HTTP/3. A port published by Docker bypasses `ufw`: see [The Docker port stays open with ufw](https://nuvits.net/en/blog/docker-port-still-open-with-ufw).

The example service is [`traefik/whoami`](https://github.com/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

```bash
mkdir -p ~/caddy/conf && cd ~/caddy
```

```ini caddy/.env
APP_DOMAIN=app.example.com
```

```caddy caddy/conf/Caddyfile
{$APP_DOMAIN} {
	reverse_proxy whoami:80
}
```

```yaml caddy/docker-compose.yml
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:
```

Validate, start and test:

```bash
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
```

`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](https://hub.docker.com/_/caddy) 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

```bash
mkdir -p ~/traefik && cd ~/traefik
```

```ini traefik/.env
APP_DOMAIN=app.example.com
ACME_EMAIL=you@example.com
```

```yaml traefik/docker-compose.yml
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:
```

```bash
docker compose config -q
docker compose up -d
docker compose logs traefik
curl -I http://app.example.com
curl https://app.example.com
```

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`:

```yaml
  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
```

```bash
docker compose up -d
curl https://api.example.com
```

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:

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

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

```caddy
api.example.com {
	reverse_proxy api:80
}
```

```bash
docker compose up -d
docker compose exec -w /etc/caddy caddy caddy reload
curl https://api.example.com
```

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](https://doc.traefik.io/traefik/reference/install-configuration/providers/docker/) warns that if Traefik is attacked, the attacker might get access to the host, and the [Docker documentation](https://docs.docker.com/engine/security/#docker-daemon-attack-surface) 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:

```bash
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro docker:29.10.1-cli docker stop traefik-api-1
```

`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](https://github.com/Tecnativa/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](https://caddyserver.com/docs/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](https://github.com/lucaslorentz/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](https://caddyserver.com/docs/automatic-https). 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](https://coolify.io/docs/core/networking/proxy/overview) uses Traefik by default and accepts Caddy as an alternative, and [Dokploy](https://docs.dokploy.com/docs/core/architecture) uses Traefik. The comparison [Coolify vs Dokploy](https://nuvits.net/en/blog/coolify-vs-dokploy-vps-comparison) 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

- If Caddy answers `502`, the guide [Fix Caddy 502 Bad Gateway and HTTPS errors with Docker](https://nuvits.net/en/blog/fix-caddy-docker-502-bad-gateway-https-vps) covers the causes.
- To see Caddy in front of a real application, follow [How to install Portainer with Docker and Caddy on a VPS](https://nuvits.net/en/blog/install-portainer-docker-caddy-vps).
- To pick a server, see the [Docker VPS](https://nuvits.net/en/docker-vps) and [Linux VPS](https://nuvits.net/en/linux-vps) plans, with Ubuntu 24.04. If you would rather use a panel, there is the [Coolify VPS](https://nuvits.net/en/coolify-vps).
