问题背景
docker启动Prometheus,想要热加载 alertmanager 的配置文件,所以开启配置 web.enable-lifecycle
启动命令
docker run -p 9090:9090 -v /opt/docker_dir/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /opt/docker_dir/prometheus/rules/:/usr/local/prometheus/rules/ bitnami/prometheus --web.enable-lifecycle
报错信息
ts=2024-05-31T07:58:02.927Z caller=main.go:521 level=error msg="Error loading config (--config.file=prometheus.yml)" file=/opt/bitnami/prometheus/prometheus.yml err="open prometheus.yml: no such file or directory"
ts=2024-05-31T07:58:02.927Z caller=main.go:521 level=error msg="Error loading config (--config.file=prometheus.yml)" file=/opt/bitnami/prometheus/prometheus.yml err="open prometheus.yml: no such file or directory"
问题分析
--config.file=prometheus.yml 表示想通过这种方式加载配置文件,但是找不到。猜测虽然我们前面已经通过映射加入配置文件,但是加入--web.enable-lifecycle参数后,可能会先自动检查--config.file=有没有值,检查没有运行命令这个配置项,所以报错
解决办法
再在后面加入--config.file这个配置
docker run -p 9090:9090 -v /opt/docker_dir/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /opt/docker_dir/prometheus/rules/:/usr/local/prometheus/rules/ bitnami/prometheus --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml
运行成功