How to persist data in Prometheus running in a Docker container?

眉间皱痕 提交于 2020-12-01 08:23:11

问题


I'm developing something that needs Prometheus to persist its data between restarts. Having followed the instructions

$ docker volume create a-new-volume
$ docker run \
    --publish 9090:9090 \
    --volume a-new-volume:/prometheus-data \
    --volume "$(pwd)"/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

I have a valid prometheus.yml in the right directory on the host machine and it's being read by Prometheus from within the container. I'm just scraping a couple of HTTP endpoints for testing purposes at the moment.

But when I restart the container it's empty, no data from the previous run. What am I missing from my docker run ... command to persist the data into the a-new-volume volume?


回答1:


Use the default data dir, which is /prometheus. To do that, use this line instead of what you have in your command:

...
--volume a-new-volume:/prometheus \
...

Found here: https://github.com/prometheus/prometheus/blob/master/Dockerfile

Surprisingly is not mentioned in the image docs



来源:https://stackoverflow.com/questions/50009065/how-to-persist-data-in-prometheus-running-in-a-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!