Skip to content

Update Caddyfile without container restart

Lead paragraph: Restarting Caddy just to apply a Caddyfile change introduces unnecessary downtime and breaks active connections. A practicing Lead DevOps knows that caddy reload signals the daemon to re-read the configuration and refresh HTTP handlers on the fly, preserving existing sessions. In this note we cover a typical docker-compose setup where Caddyfile lives on the host, the exact reload command, built-in validation tools, and the common pitfall of reaching for a restart instead.

Why reload instead of restart

A reload signal tells the Caddy daemon to reparse the Caddyfile and apply new routing rules without stopping the process. All active TCP and HTTP connections remain intact, and the worker processes restart gracefully. A full restart tears down every session, waits for the container to stop and start again, and in orchestration platforms may trigger redundant rescheduling. In self-hosted environments where services share a host without automatic failover, reload saves minutes and avoids avoidable outages.

Scenario: mounting Caddyfile via volume in docker-compose

A common self-hosted pattern stores the Caddyfile on the host machine and mounts it read‑only into the container. Example docker-compose.yml:

services:
  caddy:
    image: caddy:latest
    container_name: caddy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
    restart: unless-stopped

The :ro flag prevents the container from accidentally overwriting the config, while caddy reload reads it as a regular file. After editing the host’s Caddyfile, entering the container and running the reload command applies changes without recreating the container.

The caddy reload command for applying changes

The command is straightforward and requires no extra flags with a standard Caddy installation:

docker exec caddy caddy reload

If Caddy runs directly on the host (binary only), execute:

caddy reload

Caddy locates the config at the path set at startup (default /etc/caddy/Caddyfile), validates its structure, and activates the new rules. Outcome logging appears in docker logs caddy or the system journal when running outside Docker.

Tip

With docker compose a one‑liner on the host suffices: docker compose exec caddy caddy reload. Verify the container is running and reachable before executing.

Checking config: caddy validate and caddy fmt

Before reloading, it’s prudent to confirm the Caddyfile syntax is sound. Two built‑in utilities serve this purpose:

caddy validate
caddy fmt

caddy validate parses the file and returns exit code 0 on success; a non‑zero value signals a parsing error. caddy fmt reformats the file to match Caddy’s style, useful after manual edits to maintain consistency. Both operate without starting the daemon, making them ideal for CI/CD pipelines or pre‑deploy hooks.

Warning

Skipping caddy validate during frequent edits will cause caddy reload to fail silently, leaving the previous working configuration active and potentially masking the real issue.

Common mistake: restarting container instead of reload

The most frequent error is running docker restart caddy or docker compose up -d after modifying the Caddyfile. This produces three negative outcomes:

  1. Connection breakage – all current requests return 502 Bad Gateway.
  2. Temporary state loss – any in‑container caches or transient files (rare for Caddy, but possible with custom plugins) are cleared.
  3. Host‑side overhead – container pull/restart cycles consume time, especially for larger images.

The correct workflow: edit the host Caddyfile → run caddy validate → execute caddy reload. Reserve a full restart for Caddy version upgrades or base image updates.

Practical example of checking after reload

Confirm that changes took effect with these steps:

# 1. Trigger reload
docker exec caddy caddy reload

# 2. Validate immediately after
caddy validate && echo "Config OK"

# 3. Inspect live logs for reload messages
docker logs caddy --tail 5 | grep -i "reloaded\|config"

# 4. Send a test request
curl -s -o /dev/null -w "%{http_code}" http://localhost/

If curl returns the expected status code (200, 301, etc.) and logs show no errors, the new Caddyfile is active. Should caddy reload encounter a problem, it rolls back to the last valid configuration, so always start troubleshooting with caddy validate.