如何将 Prometheus 运行 中的数据保存在 Docker 容器中?
How to persist data in Prometheus running in a Docker container?
我正在开发需要 Prometheus 在重启之间保留其数据的东西。已按照说明进行操作
$ 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
我在主机的正确目录中有一个有效的 prometheus.yml
,Prometheus 正在从容器中读取它。目前我只是为了测试目的抓取了几个 HTTP 端点。
但是当我重新启动容器时它是空的,没有来自之前 运行 的数据。我的 docker run ...
命令将数据保存到 a-new-volume
卷中缺少什么?
使用默认数据目录,即/prometheus
。为此,请使用此行而不是命令中的内容:
...
--volume a-new-volume:/prometheus \
...
在此处找到:https://github.com/prometheus/prometheus/blob/master/Dockerfile
居然没有提到image docs
我今天遇到了同样的问题,但我使用的是 docker 作曲家文件。因此,总结其他答案的评论中的所有内容以及对我有用的内容。如果通过 yaml
撰写文件设置 Prometheus docker...
首先在主机上为卷创建一个文件夹,例如:
$ mkdir /tmp/prometheus
然后将文件夹所有者更改为 nobody
,喜欢(如果需要,请使用 sudo
):
$ chown 65534:65534 /tmp/prometheus
然后在yaml
配置文件中添加卷:
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- 9090:9090
volumes:
- /tmp/prometheus:/prometheus
- ./prometheus.yml:/etc/prometheus/prometheus.yml
应该可以了。
我正在开发需要 Prometheus 在重启之间保留其数据的东西。已按照说明进行操作
$ 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
我在主机的正确目录中有一个有效的 prometheus.yml
,Prometheus 正在从容器中读取它。目前我只是为了测试目的抓取了几个 HTTP 端点。
但是当我重新启动容器时它是空的,没有来自之前 运行 的数据。我的 docker run ...
命令将数据保存到 a-new-volume
卷中缺少什么?
使用默认数据目录,即/prometheus
。为此,请使用此行而不是命令中的内容:
...
--volume a-new-volume:/prometheus \
...
在此处找到:https://github.com/prometheus/prometheus/blob/master/Dockerfile
居然没有提到image docs
我今天遇到了同样的问题,但我使用的是 docker 作曲家文件。因此,总结其他答案的评论中的所有内容以及对我有用的内容。如果通过 yaml
撰写文件设置 Prometheus docker...
首先在主机上为卷创建一个文件夹,例如:
$ mkdir /tmp/prometheus
然后将文件夹所有者更改为 nobody
,喜欢(如果需要,请使用 sudo
):
$ chown 65534:65534 /tmp/prometheus
然后在yaml
配置文件中添加卷:
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- 9090:9090
volumes:
- /tmp/prometheus:/prometheus
- ./prometheus.yml:/etc/prometheus/prometheus.yml
应该可以了。