Config is not readable using PUID 472 and PGID 0

  • What Grafana version and what operating system are you using?
    grafana/grafana:latest using docker 20.10.17 and docker-compose 1.29.2 running on 5.18.0-1-amd64 Debian 5.18.2-1 (2022-06-06) x86_64 GNU/Linux

  • What are you trying to achieve?
    Set up an instance of Grafana with access to grafana.ini in a locally mounted folder

  • How are you trying to achieve it?
    Used a docker-compose.yml file and a .env file to manage configuration

  • What happened?
    The following errors in the log file:

$ docker-compose --file /srv/grafana/docker-compose.yml logs
Attaching to grafana
grafana    | GF_PATHS_CONFIG='/srv/grafana/config' is not readable.
grafana    | GF_PATHS_DATA='/srv/grafana/data' is not writable.
grafana    | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
grafana    | logger=settings t=2022-11-22T17:18:14.42336638Z level=error msg="failed to parse \"/srv/grafana/config\": open /srv/grafana/config: no such file or directory"
  • What did you expect to happen?
    For the container to start normally

  • Can you copy/paste the configuration(s) that you are having problems with?
    docker-compose.yml:

version: "3"
services:
  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    hostname: ${HOSTNAME}
    user: ${PUID}:${PGID} 
    environment:
      - GF_PATHS_CONFIG=${APPDATA}/config
      - GF_PATHS_DATA=${APPDATA}/data
    volumes:
      - ${APPDATA}/config:/etc/grafana/
      - ${APPDATA}/config/grafana.ini:/etc/grafana/grafana.ini # test
      - ${APPDATA}/data:/var/lib/grafana
    ports:
      - "3000:3000"
    restart: always

.env file:

# User ID and Group ID
PUID=472
PGID=0
# Directory locations
APPDATA=/srv/grafana
# Host specifics
HOSTNAME=services

Steps followed to create environment:

$ cd /srv/grafana
$ mkdir config/ data/
$ sudo chown -R 472:0 config/ data/
$ ls -la
total 48
drwxr-xr-x  8 idsvc idsvc 4096 Nov 22 10:29 .
drwxr-xr-x 34 idsvc idsvc 4096 Nov 22 10:12 ..
drwxr-xr-x  2   472 root  4096 Nov 22 10:29 config
drwxr-xr-x  2   472 root  4096 Nov 22 10:29 data
-rw-r--r--  1 idsvc idsvc 1482 Nov 22 10:15 docker-compose.yml
-rw-r--r--  1 idsvc idsvc  287 Nov 22 10:18 .env

Confirmation of configuration:

$ docker-compose --file /srv/grafana/docker-compose.yml config
services:
  grafana:
    container_name: grafana
    environment:
      GF_PATHS_CONFIG: /srv/grafana/config
      GF_PATHS_DATA: /srv/grafana/data
    hostname: services
    image: grafana/grafana-oss:latest
    ports:
    - published: 3000
      target: 3000
    restart: always
    user: '472:0'
    volumes:
    - /srv/grafana/config:/etc/grafana:rw
    - /srv/grafana/config/grafana.ini:/etc/grafana/grafana.ini:rw
    - /srv/grafana/data:/var/lib/grafana:rw
version: '3'

Environment values from running container:

$ docker exec grafana env
PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=services
GF_PATHS_CONFIG=/srv/grafana/config
GF_PATHS_DATA=/srv/grafana/data
GF_PATHS_HOME=/usr/share/grafana
GF_PATHS_LOGS=/var/log/grafana
GF_PATHS_PLUGINS=/var/lib/grafana/plugins
GF_PATHS_PROVISIONING=/etc/grafana/provisioning
HOME=/home/grafana

Mounts from running container:

$ docker container inspect grafana -f '{{range .Mounts}}{{.Type}}:{{.Source}}:{{.Destination}}{{println}}{{ end }}'
bind:/srv/grafana/config/grafana.ini:/etc/grafana/grafana.ini
bind:/srv/grafana/config:/etc/grafana
bind:/srv/grafana/data:/var/lib/grafana

I have followed the direction to use user 472 (grafana) and group 0 (root). I expected grafana.ini to be created on initial run.

1 Like

Issue resolved.

Container Configuration

These command were used to set up the environment:

cd /srv/grafana
mkdir config/ data/ logs/
docker run --rm --entrypoint /bin/bash grafana/grafana-oss:latest -c 'cat $GF_PATHS_CONFIG' > grafana.ini
mv grafana.ini config/
sudo chown -R 472:0 config/ data/ logs/
docker-compose --file /srv/grafana/docker-compose.yml up --detach

This process creates the directories that will be used to mount the hosted volumes, then grabs a copy of the grafana.ini file from the same grafana version used in the docker-compose.yml file and places it in the appropriate directory. Ownership of all the directories and contents is then set to the grafana user and root group.

Docker Compose

The following is the docker-compose.yml used:

version: "3"
services:
  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    hostname: ${HOSTNAME}
    volumes:
      - ${APPDATA}/config/grafana.ini:/etc/grafana/grafana.ini
      - ${APPDATA}/data:/var/lib/grafana
      - ${APPDATA}/logs:/var/log/grafana
    ports:
      - "3000:3000"
    restart: always

The following is the .env used:

# User ID and Group ID
PUID=472
PGID=0
# Timezone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TZ=America/Edmonton
# Directory locations
APPDATA=/srv/grafana
# Host specifics
HOSTNAME=id-services

Note that the user: setting in the docker-compose.yml has been removed.

The direction I found is to either run the container as the current user added to the docker group, or by preference change the ownership to user grafana (472) and group root (0). Grabbing a blank copy of the grafana.ini file before first launch then changing ownership was what was missing.