5

I'm using docker-compose to create a Docker network of containers with InfluxDB, a python script and Grafana to harvest and visualize response codes, query times & other stats of different websites.

I am using Grafana image 7.3.0 with a volume, I have modified the paths environment variables so I'll have to use only one volume to save all the data.

When I start the Grafana container it logs:

GF_PATHS_CONFIG='/etc/grafana/grafana.ini' is not readable.
GF_PATHS_DATA='/etc/grafana/data' is not writable.
GF_PATHS_HOME='/etc/grafana/home' is not readable.

You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-

docker-container-to-5-1-or-later

mkdir: can't create directory '/etc/grafana/plugins': Permission denied

But here is the thing, I'm not migrating from below 5.1 I'm not even migrating at all!

So I tried to follow their instruction to change permissions of files but it did not worked.

I tried to set the user id in the docker-compose but it did not help.

(as-said in the docs 472 == post 5.1, 104 == pre 5.1 but both did not worked)

I can't even change permissions manually (which is not a satisfying solution btw) because the container is crashing.

I normally don't ask questions because they already have answers but I've seen no one with this trouble using 7.3.0 so I guess it's my time to shine Haha.

Here is my docker-compose.yml (only the grafana part)

version: '3.3'

services:
  grafana:
    image: grafana/grafana:7.3.0
    ports:
      - '3000:3000'
    volumes:
      - './grafana:/etc/grafana'
    networks:
      - db-to-grafana
    depends_on:
      - db
      - influxdb_cli
    environment:
      - GF_PATHS_CONFIG=/etc/grafana/grafana.ini
      - GF_PATHS_DATA=/etc/grafana/data
      - GF_PATHS_HOME=/etc/grafana/home
      - GF_PATHS_LOGS=/etc/grafana/logs
      - GF_PATHS_PLUGINS=/etc/grafana/plugins
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
   user: "472"

Thank you very much for your potential help!

Edit : I've been wondering if there is a grafana user in latest version (8.0), I think that build a home dir for grafana using a Dockerfile could be the solution I just need to find that user.

Loys Caucheteux
  • 259
  • 1
  • 2
  • 8
  • https://grafana.com/docs/grafana/latest/installation/docker/#migrate-to-v73-or-later – Jan Garaj Jul 02 '21 at 15:32
  • @JanGaraj Thanks for your help ! I've saw that docs and again i'm not migrating, I already kind of tried this strat but I think I could have done it wrong. Could you clarify your point please? Thanks again – Loys Caucheteux Jul 04 '21 at 11:57
  • What happens when you omit the `user: "472"` parameter in compose? It should be run as root I guess, can't you still access it? Another solution might be to move your grafana folder from /etc/ to another folder and change `GF_PATHS_*` envars accordingly. To change permissions at the start, you can override grafana dockerfile or entrypoint, you'd need the grafana file source code and modify their entrypoint – Yamuk Jul 04 '21 at 14:35
  • @Yamuk When I omits the user it's the same problem, I've found the solution anyway, the problem was coming from my volume wich was created by root user and therefor unavailable to grafana. Noob mistake a bit, so all i finally did was chown -R /path/to/volume and chmod -R 777 /path/to/volume. And remove the env variables because they were messing with grafana setup. I 'll post an answer soon. – Loys Caucheteux Jul 05 '21 at 07:58

3 Answers3

12

I'm here to close this subject.

So this was kind of a noob mistake but I could not have known. The problem came from the fact that Grafana won't chown and chmod the volume folder. The error does not occures but it won't work because it does not save the data.

The solution was to remove the env variables and changing permissions of the local './grafana' folder wich contained the volume.

So I did

chown -R <personal local user> /path/to/local/volume/folder && \
chmod -R 777 /path/to/local/volume/folder

And now it works normally Here is my new docker compose

   docker-compose.yml   
    grafana:
        image: grafana/grafana
        ports:
          - '3000:3000'
        volumes:
          - './grafana:/var/lib/grafana'
        networks:
          - db-to-grafana
        depends_on:
          - db
          - influxdb_cli

Thanks everybody four your help !

Loys Caucheteux
  • 259
  • 1
  • 2
  • 8
2

You might have taken a basic understanding of this error. It happens mainly because of permission. To tackle this you can follow any one of the below steps: Anyone can work for you.

  1. You can run this cmd while running up docker-compose

    docker-compose up --force-recreate

  2. In your compose .yml file add the user as root like:

version: "3.8"
services:
  grafana:
      
    image: "grafana/grafana:8.2.6"
    command: bash -c "docker login -u user -p password && /run.sh"
    ports:
      - "192.168.1.31:5433:3000"
    volumes:
      - /home/grafana_hosting/app_data:/var/lib/grafana
    user: "root:root"
markalex
  • 8,623
  • 2
  • 7
  • 32
Sumanta
  • 29
  • 5
1

Just replace your user's id that you will get on the following command:

$ id -u

Im running 'id -u' in my terminal and getting '1000'. SO, I replaced user: "xxxx" to user: "1000" in docker-compose.yml

version: '3.3'
services:
  grafana:
    image: grafana/grafana:7.3.0
    ports:
      - '3000:3000'
    volumes:
      - './grafana:/etc/grafana'
    networks:
      - db-to-grafana
    depends_on:
      - db
      - influxdb_cli
    environment:
      - GF_PATHS_CONFIG=/etc/grafana/grafana.ini
      - GF_PATHS_DATA=/etc/grafana/data
      - GF_PATHS_HOME=/etc/grafana/home
      - GF_PATHS_LOGS=/etc/grafana/logs
      - GF_PATHS_PLUGINS=/etc/grafana/plugins
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
   user: "1000"
Hannan
  • 109
  • 9