Loading...
 

Greg's Tech blog

Prometheus & docker permission denied error

Wednesday 12 of May, 2021

I'm moving  all my self-hosted services to docker - specifically, docker compose.  I'm using this config for prometheus:

prometheus:

    image: prom/prometheus:latest

    # privileged: true

    volumes:

      -  /mnt/samba/Docs/docker/config/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml

      -  /mnt/samba/Docs/docker/config/prometheus/data:/prometheus

      # -  /data/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml

      # -  /data/prometheus/data:/prometheus

      # -  ./alertmanger/alert.rules:/alert.rules

    command:

      - '--config.file=/etc/prometheus/prometheus.yml'

    ports:

      - '9090:9090'

I ws getting this  error  on startup:
ERROR: for prometheus Cannot start service prometheus: OCI runtime create failed: container_linux.go:367: starting container process caused: chdir to cwd ("/prometheus") set in config.json failed: permission denied: unknown

After much testing, I added the user:"1000" command to force the container to run as my account.  I'll admit I  have a lot to learn about docker and permissions.

Here is the final yml:

prometheus:

    image: prom/prometheus:latest

    user: "1000"

    # privileged: true

    volumes:

      -  /mnt/samba/Docs/docker/config/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml

      -  /mnt/samba/Docs/docker/config/prometheus/data:/prometheus

      # -  /data/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml

      # -  /data/prometheus/data:/prometheus

      # -  ./alertmanger/alert.rules:/alert.rules

    command:

      - '--config.file=/etc/prometheus/prometheus.yml'

    ports:

      - '9090:9090'