Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Prometheus container exits because its config file is missing

Error/etc/prometheus/prometheus.yaml: no such file or directory

Short answer

Prometheus reads one config file, set with --config.file. The container exits when nothing exists at that exact path. In Docker Compose the usual reasons are a mismatch between the file name and the mount target, a command override that dropped the flag, or a host path that Docker turned into an empty directory.

  • Applies to Prometheus 3, Docker Compose 2, Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the resolved Compose file. It shows the real host path of each mount and any command that replaces the image default.

    docker compose config
    docker compose logs --tail 20 prometheus
  2. 2Match what you see, then jump to its fix

    1. 1The error names a file such as prometheus.yaml, but the file you mounted is called prometheus.yml (or the other way round)The mount target and the config file name do not matchFix
    2. 2The service has a command: list in Compose, and the log complains about the config file or about a path you never setA command: entry replaced the image defaultsFix
    3. 3The mount source on the host is a directory although you meant a fileThe host file did not exist, so Docker created a directoryFix
    4. 4Your volume line mounts a folder onto /etc/prometheusA whole directory was mounted over /etc/prometheus and it lacks the fileFix

What does the error look like?

  • /etc/prometheus/prometheus.yaml: no such file or directory

Cause 1 of 4

The mount target and the config file name do not match

1Check

Prometheus loads the file named by --config.file. The official Docker example mounts the host file onto /etc/prometheus/prometheus.yml, so a differently named target leaves that path empty.

docker compose config | grep -n -A3 "volumes:"

2Fix

Make the name in the volume line identical to the path Prometheus is told to load. The simplest way is to follow the documented example.

# compose.yaml
services:
  prometheus:
    image: prom/prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

3Verify

Recreate the container and confirm it stays up.

docker compose up -d --force-recreate prometheus
docker compose ps prometheus

Confirmed by prometheus.io

Did this fix it?

Cause 2 of 4

A command: entry replaced the image defaults

1Check

In Compose, command overrides the image's default command. The Prometheus install page warns that extra parameters overwrite the defaults, so you must repeat the ones you still need.

docker compose config | grep -n -B1 -A4 "command:"

2Fix

Put the config flag back next to the flags you added.

services:
  prometheus:
    image: prom/prometheus
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      # your other flags go here, one per line

3Verify

The service starts and stays in the running state.

docker compose up -d prometheus
docker compose ps prometheus

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 4

The host file did not exist, so Docker created a directory

1Check

With the short volume syntax, a missing host path is created as a directory. Relative paths are resolved from the folder of the Compose file, not from where you ran the command.

ls -ld ./prometheus.yml

2Fix

Stop the stack, remove the empty directory, create the real file in the Compose file's folder, then start again. Use the long volume syntax with create_host_path set to false if you want a missing path to fail loudly.

docker compose down
rmdir ./prometheus.yml
# create prometheus.yml next to compose.yaml, then:
docker compose up -d
# compose.yaml, long syntax
volumes:
  - type: bind
    source: ./prometheus.yml
    target: /etc/prometheus/prometheus.yml
    bind:
      create_host_path: false

3Verify

The path on the host is now a regular file, and the service runs.

ls -l ./prometheus.yml
docker compose ps prometheus

Confirmed by docs.docker.com

Did this fix it?

Cause 4 of 4

A whole directory was mounted over /etc/prometheus and it lacks the file

1Check

A bind mount hides whatever the container directory held before. The documented directory form only works when the host folder itself contains prometheus.yml.

ls -l ./config

2Fix

Add the config file to that host folder, or mount only the single file as in the first cause.

# host folder must contain prometheus.yml
volumes:
  - ./config:/etc/prometheus

3Verify

Restart the service and check it is running.

docker compose up -d --force-recreate prometheus
docker compose ps prometheus

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Keep one name for the config file (prometheus.yml) in the repository, in Compose and in any command: flag.
  • Run docker compose config after every edit to see the real paths before starting the stack.
  • Use the long volume syntax with create_host_path set to false for config files, so a typo fails at start instead of making a directory.
  • When you add a command: entry, copy every flag the image default needs, not only the new one.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.