Starting docker container results in permission denied

Container file system permissions need fixing

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 n should no longer fails with permission denied, if it does then a certain solution would be to chmod 777 -R <folder> to grant complete access, a little drastic you may think, you could try the following if still stuck, pulled from the grafana documentation:

mkdir data # creates a folder for your data
ID=$(id -u) # saves your user id in the ID variable# starts grafana with your user id and using the data folder
docker run -d --user $ID --volume "$PWD/data:/var/lib/grafana" -p 3000:3000 grafana/grafana:7.2.1

 

 

Tags:
docker
docker-compose

v1.9.1

© ScottFreeIT.com 2020