version: '3'
services:
grafana:
image: grafana/grafana:5.2.4
user: "1001"
volumes:
- ./gfdata:/var/lib/grafana
ports:
- 3000:3000
I hope this helps clearing up some of the confusion.
it seems when you are running docker with root rights eg. sudo usermod -a -G docker $USER
then the user id to set will be 0 (sudo id -u v/s id -u)
Just to share my experience with the same permissions errors:
Specifying the user:"$UID", initially didn’t work. It was throwing an error - that is until I first did “docker rm grafana” (where grafana is my container name) to clear out the failed container.
Now it is running great.
I’kind of having the same issue. The user: "1001"
option didn’t work although id -u
said 1001
.
When I start grafana with changed permissions as given on this page (at the very bottom where it says Modifying permissions everything runs smoothly (for "<your volume mapping here>"
I set two volumes to my local filesystem to make the data persistent).
I thought once started with the given commands, permissions would persist. I was wrong. Yet when I tried to start the whole thing with docker-compose everything reverts “not working”.
So my question(s) is: How do I have to write docker-compose.yml to change the permissions on startup OR how to make the permission changes permanent (with a bit of work up-front).
The reason I want to have it setup like this is, that I want to regularly update (reinstall) my hostsystem. All data that need to be persistant are on an external diskstation. --> When I install new hostsystem I would like to docker-compose up
and have everything I need running…
Thank you for your help!
To save everyone some headaches. You need to add both UID (user ID) and GID (group ID).
version: '3'
services:
stats-app:
image: grafana/grafana
user: "$UID:$GID"
network_mode: host
ports:
- 3000:3000
volumes:
- ./data/grafana:/var/lib/grafana
For me run exec with root admin :
$ docker exec -ti --user root id_grafana /bin/ash
/usr/share/grafana $ ls -la /var/lib/grafana/
total 5684
drwxr-xr-x 5 104 107 4096 Dec 8 16:35 .
drwxr-xr-x 1 root root 4096 Oct 5 16:28 ..
-rw-r--r-- 1 104 107 5795840 Dec 8 16:35 grafana.db
drwxr-xr-x 2 104 107 4096 Jun 23 2020 plugins
drwx------ 2 root root 4096 Dec 9 2020 png
drwx------ 18 104 107 4096 Jun 29 2020 sessions
/usr/share/grafana # chown -R 104:107 /var/lib/grafana/png/
I literally have no idea why this worked for me, but I think I have a solution.
TL;DR: user: ":"
worked for me
What didn’t work for me:
Setting data folder ownership to 472:472
Setting “user:” to something meaningful, like my UID or UID:GID, or some IDs that correspond to the ownership of the host data directory
What did work:
Setting host folder permissions to 777, but I didn’t like it. I noticed though that with 777 permissions the files created by grafana were owned by some random user IDs, that might or might not depend on the “user:” setting provided in the docker-compose.yml
So I tried setting “user:” to “$UID:$GID”, but got a warning saying
WARN[0000] The "UID" variable is not set. Defaulting to a blank string.
WARN[0000] The "GID" variable is not set. Defaulting to a blank string.
But in this case, the files created by the docker container were owned by my host user, not by a random UID (which was the case with all the other options, regardless of the user setting). Then I decided to get rid of warning and just set it to a blank string. And it worked, now all the files created by grafana are owned by my host user and everything works fine.
For some reason though user: ""
doesn’t work, but user: ":"
does.
It would be great if some docker guru explained this behaviour though.
Or doing it even more easier way:
on your docker-machine write the command on terminal
[root@docker ~]# id
uid=0(root) gid=0(root) groups=0(root)
since I am logged in as root so in my docker-compose.yml file add this line under your grafana service blueprint e.g.
grafana-app:
image: 'grafana/grafana-oss'
## output based on the command line
user: "0:0"
restart: unless-stopped
container_name: grafana
ports:
- '3000:3000'
volumes:
- ./grafana:/var/lib/grafana
then run the docker-compose up
command and should work fine. No need to manually give permission for the /var/lib/grafana folder.