1. The problem I’m having:
I am trying to use this page (Monitoring Caddy with Prometheus and Grafana - TheDeveloperCafe ) to set up Prometheus and monitor my Caddy docker container, then eventually monitor my various web facing containers as well. However, I cannot test the metrics because it is locked to only accepting requests from localhost which is the container.
2. Error messages and/or full log output:
$ curl -X GET localhost:2019/metrics
curl: (52) Empty reply from server
3. Caddy version:
2.8.4
4. How I installed and ran Caddy:
docker pull lucaslorentz/caddy-docker-proxy
docker create network caddy
a. System environment:
Ubuntu 24.04.1 LTS
Docker version 27.3.1
lucaslorentz/caddy-docker-proxy 2.9.2
b. Command:
docker compose up -d
c. Service/unit/compose file:
services:
caddy:
image: lucaslorentz/caddy-docker-proxy:ci-alpine
container_name: caddy
ports:
- 0.0.0.0:80:80
- 0.0.0.0:443:443
- 0.0.0.0:443:443/udp
- 0.0.0.0:2019:2019
environment:
- CADDY_INGRESS_NETWORKS=caddy
- TZ="Europe/London"
networks:
- caddy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./data:/data
- ./config:/config
restart: unless-stopped
labels:
caddy.email: info@mydomain.co.uk
networks:
caddy:
external: true
d. My complete Caddy config:
{
email info@mydomain.co.uk
}
5. Links to relevant resources:
1. Caddy version (caddy version):
v2.5.1 h1:bAWwslD1jNeCzDa+jDCNwb8M3UJ2tPa8UZFFzPVmGKs=
2. How I run Caddy:
I run Caddy using the official docker container, Docker Hub , with vanilla settings. I run caddy (and other services) directly via docker run, no additional orchestration layer (no docker-compose etc).
docker run --name caddy \
--detach \
--publish 0.0.0.0:80:80 \
--publish 0.0.0.0:443:443 \
--restart always \
-v ${HERE}/Caddyfile:/etc/caddy/Caddyfile \
-v ${…
Mohammed90
(Mohammed Al Sahaf)
March 29, 2025, 11:04pm
2
There are multiple ways to do it. You can change the listening address of the admin endpoint to something different.
You can also define another site on a different port and use the metrics
directive to serve metrics on that address/port.
The Caddyfile configuration has changed a bit since that blog post was published. I recommend you refer to our official documentation.
Thanks for your quick reply!
Your first suggestion to “change the listening address of the admin endpoint to something different” didn’t seem to work. Here are my settings and output:-
services:
caddy:
image: lucaslorentz/caddy-docker-proxy:ci-alpine ## <<
container_name: caddy
ports:
- 0.0.0.0:80:80
- 0.0.0.0:443:443
- 0.0.0.0:443:443/udp
- 0.0.0.0:2020:2020 ## <<
environment:
- TZ="Europe/London"
- CADDY_INGRESS_NETWORKS=caddy
- CADDY_ADMIN=0.0.0.0:2020 ## <<
networks:
- caddy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./data:/data
- ./config:/config
restart: unless-stopped
labels:
caddy.email: info@mydomain.co.uk
caddy.admin: 0.0.0.0:2020 ## <<
caddy.metrics: ""
networks:
caddy:
external: true
… which gave me this Caddyfile (made by the lucaslorentz docker image) …
{
admin 0.0.0.0:2020
email info@mydomain.co.uk
metrics
}
… and this is the network connections list …
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10720/docker-proxy
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 10725/docker-proxy
tcp 0 0 0.0.0.0:2020 0.0.0.0:* LISTEN 10741/docker-proxy
… but no joy with telnet or curl …
$ telnet 0.0.0.0 2020
Trying 0.0.0.0...
Connected to 0.0.0.0.
Escape character is '^]'.
Connection closed by foreign host.
$ curl -X GET localhost:2020/metrics
curl: (56) Recv failure: Connection reset by peer
and this is the network connections list in the caddy container (showing the restricted 127.0.0.0 localhost for the admin port 2019) …
/ $ netstat -ntap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2019 0.0.0.0:* LISTEN 1/caddy
tcp 0 0 :::443 :::* LISTEN 1/caddy
tcp 0 0 :::80 :::* LISTEN 1/caddy
… so that did not work
NEXT, to “define another site on a different port and use the metrics directive to serve metrics on that address/port” …
back tomorrow.