启动prometheus docker镜像时出错,即使存在,也找不到配置文件

问题描述 投票:1回答:2

我试图用以下命令启动Prometheus docker图像

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

它给了我以下错误 -

level=info ts=2019-04-04T07:00:57.825748769Z caller=main.go:285 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-04-04T07:00:57.825814174Z caller=main.go:321 msg="Starting Prometheus" version="(version=2.8.1, branch=HEAD, revision=4d60eb36dcbed725fcac5b27018574118f12fffb)"
level=info ts=2019-04-04T07:00:57.825837922Z caller=main.go:322 build_context="(go=go1.11.6, user=root@bfdd6a22a683, date=20190328-18:04:08)"
level=info ts=2019-04-04T07:00:57.825860337Z caller=main.go:323 host_details="(Linux 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 66c91dea5c1a (none))"
level=info ts=2019-04-04T07:00:57.825884164Z caller=main.go:324 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-04-04T07:00:57.825903925Z caller=main.go:325 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-04-04T07:00:57.826527025Z caller=main.go:640 msg="Starting TSDB ..."
level=info ts=2019-04-04T07:00:57.826561753Z caller=web.go:418 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-04-04T07:00:57.832311812Z caller=main.go:655 msg="TSDB started"
level=info ts=2019-04-04T07:00:57.832352248Z caller=main.go:724 msg="Loading configuration file" filename=/prometheus-data/prometheus.yml
level=info ts=2019-04-04T07:00:57.83239727Z caller=main.go:509 msg="Stopping scrape discovery manager..."
level=info ts=2019-04-04T07:00:57.832408073Z caller=main.go:523 msg="Stopping notify discovery manager..."
level=info ts=2019-04-04T07:00:57.832414257Z caller=main.go:545 msg="Stopping scrape manager..."
level=info ts=2019-04-04T07:00:57.832420826Z caller=main.go:519 msg="Notify discovery manager stopped"
level=info ts=2019-04-04T07:00:57.832438255Z caller=main.go:505 msg="Scrape discovery manager stopped"
level=info ts=2019-04-04T07:00:57.832450272Z caller=manager.go:736 component="rule manager" msg="Stopping rule manager..."
level=info ts=2019-04-04T07:00:57.832467629Z caller=manager.go:742 component="rule manager" msg="Rule manager stopped"
level=info ts=2019-04-04T07:00:57.832470472Z caller=main.go:539 msg="Scrape manager stopped"
level=info ts=2019-04-04T07:00:57.934588178Z caller=notifier.go:521 component=notifier msg="Stopping notification manager..."
level=info ts=2019-04-04T07:00:57.934683234Z caller=main.go:708 msg="Notifier manager stopped"
level=error ts=2019-04-04T07:00:57.935159211Z caller=main.go:717 err="error loading config from \"/prometheus-data/prometheus.yml\": couldn't load configuration (--config.file=\"/prometheus-data/prometheus.yml\"): open /prometheus-data/prometheus.yml: no such file or directory"

我仔细检查,目录和配置文件存在,并检查目录和配置文件名中的拼写错误。

我错过了什么吗?

我使用的是ubuntu 18.0.4

我检查this解决方案,但它不适合我。

docker prometheus
2个回答
1
投票

问题出在这里:

docker run -v /prometheus-data ...

您创建了anonymous卷并将其安装在/ prometheus-data的容器内。

装入卷时,可能会命名或匿名。匿名卷在首次装入容器时未给出明确的名称,因此Docker为它们提供了一个随机名称,该名称在给定的Docker主机中保证是唯一的。除名称外,命名和匿名卷的行为方式相同。

因此,此匿名卷与主机上具有相同名称的目录无关。或者更准确地说,容器中的卷掩盖了主机目录。无论如何,从容器内部,目录为空。

如果要将主机目录绑定到容器中的目录,则必须提供两个args:第一个是主机目录(源),第二个是容器内的目录(目标)

docker run -v /prometheus-data:/prometheus-data ...

为了避免与-v语法混淆,最好使用--mount

最初,-v或--volume标志用于独立容器, - mount标志用于swarm服务。但是,从Docker 17.06开始,您还可以将--mount与独立容器一起使用。通常, - mount更明确,更冗长。最大的区别是-v语法将所有选项组合在一个字段中,而--mount语法将它们分开。


0
投票

尝试以下代替--config.file:

docker run -p 9090:9090  -d --mount type=bind,source=path/to/prometheus.yml,target=/etc/prometheus/prometheus.yml prom/prometheus

这就是它在Ubuntu 18.04上对我有用的方式

© www.soinside.com 2019 - 2024. All rights reserved.