Access metrics when using dockerized caddy?

The admin endpoint only listens on localhost:2019 by default, which means it will only accept requests coming from localhost (i.e. 127.0.0.1 or ::1), which means it will only accept connections coming from within the container.

You need to configure the admin endpoint to listen on all IPs if you want it to be accessible from outside the container. Configure the global option admin :2019 to make it listen to all interfaces on port 2019.

You’ll need to publish that port with Docker as well. Make sure to protect access to this port so that only trusted clients/machines can connect to it, otherwise you risk allowing anyone to manipulate Caddy’s config, and they could do some bad things.

Alternatively, you could instead set up a site in your config that publishes the metrics data, with the metrics directive:

Again, you’ll want to make sure only trusted clients have access to this, either by limiting which remote IPs are allowed to see the data. For example:

metrics.example.com {
	@nope not remote_ip private_ranges
	abort @nope

	metrics
}

This way any connection coming from public IP ranges will be aborted, and only private IP ranges will reach the metrics handler.

6 Likes