Caddy V2 was released recently and it has a bunch of improvements and a new license model which makes it more attractive as a replacement for Nginx.

Docker

You can get the docker image from docker hub caddy's image.

To do a quick test and ensure everything works:

$ docker run -d -p 8181:80 \
    -v $PWD/index.html:/usr/share/caddy/index.html \
    -v caddy_data:/data \
    caddy:2.0.0-alpine

Caddyfile

Running with a custom Caddyfile:

$ docker run -d -p 8181:80 \
    -v $PWD/Caddyfile:/etc/caddy/Caddyfile \
    -v caddy_data:/data \
    caddy:2.0.0-alpine

Reloading a caddy instance. First get the containers ID:

$ caddy_container_id=$(docker ps | grep caddy | awk '{print $1;}')

Then just issue a reload command:

$ docker exec $caddy_container_id caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile

API

Run a caddy instance using the API

$ docker run -d -p 8181:80 \
    -p 2019:2019 \
    -v caddy_data:/data \
    caddy:2.0.0-alpine
    --adapter jsonc

Save as caddy.json:

{
    "apps": {
        "http": {
            "servers": {
                "example": {
                    "listen": [":2015"],
                    "routes": [
                        {
                            "handle": [{
                                "handler": "static_response",
                                "body": "Hello, world!"
                            }]
                        }
                    ]
                }
            }
        }
    }
}
$ curl localhost:2019/load \
    -X POST \
    -H "Content-Type: application/json" \
    -d @caddy.json

TIPS

Use the caddy-json-schema plugin to generate IDE support.