无法使用 docker (prom/prometheus) 加载 prometheus.yml 配置文件

Dan*_*ano 3 docker dockerfile prometheus prometheus-alertmanager

我正在尝试使用以下自定义配置文件通过docker加载 prometheus:danilo@machine:/prometheus-data/prometheus.yml

全球的:
  scrape_interval: 15s # 默认情况下,每 15 秒抓取一次目标。

# 将这些标签附加到任何时间序列或警报时与 # 外部系统(联邦、远程存储、警报管理器)。 外部标签: 监视器:'代码实验室监视器'

# 一个只包含一个要抓取的端点的抓取配置: # 这里是 Prometheus 本身。 刮配置: # 作业名称作为标签添加job=<job_name>到从此配置中抓取的任何时间序列中。 - 工作名称:'普罗米修斯'

# Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - targets: ['localhost:8083', 'localhost:8080'] labels: my_app group: 'my_app_group'
Run Code Online (Sandbox Code Playgroud)

使用以下命令:

$ sudo docker run -p 9090:9090 prom/prometheus --config.file=/prometheus-data/prometheus.yml

该文件已经存在。但是,我收到以下消息:

level=error ts=2018-09-26T17:45:00.586704798Z caller=main.go:617 err="error loading config from \"/prometheus-data/prometheus.yml\": 无法加载配置 (-- config.file=\"/prometheus-data/prometheus.yml\"): 打开 /prometheus-data/prometheus.yml: 没有这样的文件或目录"

我正在遵循本指南:

我该怎么做才能正确加载此文件?

Kin*_*ang 9

“文件已经存在”,您的意思是该文件在您的主机上/prometheus-data/prometheus.yml吗?如果是这样,那么您需要将它绑定到您的容器中,以便 Prometheus 可以访问它。

sudo docker run -p 9090:9090 -v /prometheus-data/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
Run Code Online (Sandbox Code Playgroud)

它在文档中的Volumes & bind-mount 下进行了介绍。


Uda*_*tne 7

我正在使用 docker-compose.yaml 并且也遇到了同样的问题。我必须按如下方式设置卷详细信息。

  prometheus:
    image: prom/prometheus:v2.26.0
    user: root
    ports:
      - 9090:9090
    volumes:
      - /apps/prometheus/configs/prometheus.yaml:/etc/prometheus/prometheus.yaml
      - /data/prometheus:/prometheus
    command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml
Run Code Online (Sandbox Code Playgroud)