I'm trying to execute my docker-compose.yml file which contains prometheus and grafana configurations.
Here is my docker-compose.yml file:
version: '2'
services:
prometheus:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- /prometheus:/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3000:3000"
volumes:
- /var/lib/grafana:/var/lib/grafana
Whenever I enter docker-compose -f docker-compose.yml up command to run it, I face with these kind of errors about permission:
prometheus_1 | level=error ts=2019-06-30T16:14:42.690Z caller=main.go:723 err="opening storage failed: lock DB directory: open /prometheus/lock: permission denied"
prometheus_1 | level=error ts=2019-06-30T16:26:11.897Z caller=main.go:723 err="opening storage failed: mkdir data/: permission denied"
I don't know how to solve this problem, I already have searched over github issues and the other stackoverflow's questions, but unfortuntely none of them help!
If you don't need access from the host to these volume files, use a named volume instead of a host mount. Docker will initialize the contents of the named volume, including the permissions and ownership, avoiding permission issues like this:
version: '2'
volumes:
prometheus:
grafana:
services:
prometheus:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- prometheus:/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3000:3000"
volumes:
- grafana:/var/lib/grafana
For a general solution to solve permission issues with host mounts, the fix-perms script in my docker-base image can be used, along with an entrypoint and changes to how the container is started, to dynamically adjust the userid inside the container to match that of the volume mount.
My docker-compose up command continually returned the following:
err="opening storage failed: lock DB directory: open /prometheus/lock: permission denied"
The problem is the folder structure/files on your local machine have the incorrect file permissions and when the docker container is fired up it is unable to write to the specified location.
I fixed this by recursively chown-ing the folder with the following command:
sudo chown -R nobody:nogroup <local path>
an example, my volumes section in my docker-compose.yml looked like this:
volumes:
- /home/user/docker-volumes/prometheus:/prometheus
The colon signifies the separation of local file path : docker container file path. Applying my previous chown example above results in the following:
sudo chown -R nobody:nogroup /home/user/docker-volumes/prometheus
My docker-compose up no longer fails with permission denied!