1

I am trying to start Prometheus docker image with following command

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

and it gives me following error -

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"

I double checked, the directory and the configuration file exists, and checked for typos in directory and config file names.

Am I missing something?

I using ubuntu 18.0.4

I check this solution but it didn't work for me.

Bopsi
  • 2,090
  • 5
  • 36
  • 58

2 Answers2

2

Try the following instead of --config.file:

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

That's how it works for me on Ubuntu 18.04

meaningqo
  • 1,653
  • 10
  • 16
  • getting error running that command `Error parsing commandline arguments: unknown short flag '-d' prometheus: error: unknown short flag '-d'` – Bopsi Apr 04 '19 at 07:18
  • -d runs the docker container detached in the background. might be, that you are using an older docker version? can you try again without the -d flag? see: docs.docker.com/engine/reference/commandline/run for more information – meaningqo Apr 04 '19 at 07:29
  • 1
    You need to pass the arguments for docker before the image name, otherwise they are passed to the container as command. So prom/prometheus should be at the end in the given sample. – Andreas Jägle Apr 23 '19 at 20:19
2

The problem is here:

docker run -v /prometheus-data ...

You created anonymous volume and mounted it inside you container at /prometheus-data.

When you mount a volume, it may be named or anonymous. Anonymous volumes are not given an explicit name when they are first mounted into a container, so Docker gives them a random name that is guaranteed to be unique within a given Docker host. Besides the name, named and anonymous volumes behave in the same ways.

So this anonymous volume has nothing to do with you directory at the host with the same name. Or to be more precise the volume in the container masks the host directory. Anyway from inside your container the directory is empty.

If you want to bind you host directory to the directory in the container then you must give two args: the first is your host dir (source) and the second is the dir inside container (target)

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

In order to avoid confusion with -v syntax it is better to use --mount

Originally, the -v or --volume flag was used for standalone containers and the --mount flag was used for swarm services. However, starting with Docker 17.06, you can also use --mount with standalone containers. In general, --mount is more explicit and verbose. The biggest difference is that the -v syntax combines all the options together in one field, while the --mount syntax separates them.

ISQ
  • 2,704
  • 1
  • 14
  • 8