I have a new server running Prometheus in docker-compose. I want to be able to re-load the configuration file (prometheus.yml) without have to stop and start the container.
Of course since I persist the storage of promethues in a volume the stop and start isn't really a problem but it seems like overkill, especially since prometheus itself has such a handy api to reload configs.
I see other people with similar questions (e.g. here) but I have been unable to get those solutions to work for me. Maybe I'm overlooking something there.
docker-compose.yml
version: "3"
services:
grafana:
restart: always
container_name: grafana
image: grafana/grafana:6.2.1
ports:
- 3000:3000
volumes:
- grafanadata:/var/lib/grafana
prometheus:
restart: always
container_name: prometheus
image: prom/prometheus:v2.10.0
privileged: true
volumes:
- ./configuration/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheusdata:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.enable-admin-api'
- '--web.enable-lifecycle'
ports:
- 9090:9090
node:
restart: always
container_name: node
image: prom/node-exporter:v0.18.0
ports:
- 9100:9100
volumes:
grafanadata:
prometheusdata:
Alas, my results..
When I run curl -X POST http://localhost:9090/-/reload
the docker-compose logs give:
prometheus | level=info ts=2019-06-17T15:33:02.690Z caller=main.go:730 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
prometheus | level=info ts=2019-06-17T15:33:02.691Z caller=main.go:758 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
So the prometheus' end is working fine.. All good so far.
However, when I edit ./configuration/prometheus/prometheus.yml
the changes don't propogate to the container.
Furthermore, when I try to edit /etc/promethus/prometheus.yml
in container I see that it is read only (and as an aside, the container does not have a 'sudo' command).
Is there a docker native way to hot/live reload these config files to the container directory?
As stated, the down/start option works for now but I'm curious if there is a more elegant solution.
Prometheus can reload its configuration at runtime. If the new configuration is not well-formed, the changes will not be applied. A configuration reload is triggered by sending a SIGHUP to the Prometheus process or sending a HTTP POST request to the /-/reload endpoint (when the --web. enable-lifecycle flag is enabled).
Using Docker All Prometheus services are available as Docker images on Quay.io or Docker Hub. Running Prometheus on Docker is as simple as docker run -p 9090:9090 prom/prometheus . This starts Prometheus with a sample configuration and exposes it on port 9090.
The service file tells systemd to run Prometheus as the prometheus user, with the configuration file located in the /etc/prometheus/prometheus. yml directory and to store its data in the /var/lib/prometheus directory.
docker-compose kill -s SIGHUP prometheus
does the trick, so Vishrant was certainly on to something there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With