0

I'm new to Docker and I'm playing with volumes, images, containers and so on.

One of my last attempt was to take some data inside a container and bring them to a volume so, if I would kill the container, I would be able to re-run with the same settings as before.

To copy the content from inside the container (it's a Grafana instance) to host I used

docker cp grafana:/var/lib/grafana /home/nicola/Documenti/

Then I created the new volume with the classic docker volume create grafana-storage

Then I attached the new volume to a temporary container

docker container create --name temp -v grafana-storage:/data bash

and then I copied the old data from my host to the volume

docker cp grafana temp:/data

and deleted the temporary container.

Now, if I run a new instance of grafana with the new volume like below

docker run -d -p 3000:3000 --name=grafana \
  --volume grafana-storage:/var/lib/grafana \
  grafana/grafana-oss

The container exits with the following error

GF_PATHS_DATA='/var/lib/grafana' is not writable.

You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later

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

GF_PATHS_DATA='/var/lib/grafana' is not writable.

You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later

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

What type of permissions do I need to set to the folder I copy inside the volume?

NicoCaldo
  • 1,171
  • 13
  • 25
  • Does this answer your question? [File ownership after docker cp](https://stackoverflow.com/questions/46613326/file-ownership-after-docker-cp) – Rob Jul 14 '23 at 13:50
  • @Rob the issue is I don't know the user that Grafana uses inside its container. Also, the container exit and I can't login as superuser – NicoCaldo Jul 14 '23 at 13:53
  • You could inspect the Dockerfile used by the image. For example, [this one](https://github.com/grafana/grafana-docker/blob/master/Dockerfile) indicates UID and GID are set to 472. Alternatively, can you just create a fresh container and inspect the GID and GID there after copying the files? – Rob Jul 14 '23 at 14:02
  • @Rob I'm trying the `tar` option but I'm unable to use it for the whole folder – NicoCaldo Jul 14 '23 at 14:10
  • In theory, tar should work for both single files and directories. What exact command are you using and is there any error message? – Rob Jul 17 '23 at 06:15
  • @ROb if I use `tar -cf - . --mode u=+r,g=-rwx,o=-rwx --owner root --group root | docker cp - temp:/data` to copy the current folder inside the volume I got an _successfully copied 0B to temp:/data_ so it has copied nothing – NicoCaldo Jul 18 '23 at 14:34
  • While using `tar -cf grafana.tar grafana` correctly creates the archive – NicoCaldo Jul 18 '23 at 14:48

0 Answers0