Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover configuration of Grafana-docker persistent volume?

I did a Grafana-docker deployment with persistent storage as said in their GitHub for doing tests for my company. I did exactly as they say (I paste) and it works:

# create /var/lib/grafana as persistent volume storage
docker run -d -v /var/lib/grafana --name grafana-storage busybox:latest

# start grafana
docker run \
  -d \
  -p 3000:3000 \
  --name=grafana \
  --volumes-from grafana-storage \
  grafana/grafana

Problem: if I restart the server where it runs, "I" lose all the configurations, I mean, I cannot find how to start it taking the same volume (I'm sure it's there, but I could not find the way to start again the image with them). I also do a docker volume ls and the output is quite difficult to understand

I was checking on the documentation and trying commands, but no result, I was looking for the answer, but I could not find exactly how to recover the config in this case. How I can start it recovering the old volume, so, all the configs, dashboards, etc? Also: if possible, could also someone link to me the right guide to read and understand this?

In advance, thanks a lot.

like image 297
xCovelus Avatar asked Aug 17 '17 08:08

xCovelus


2 Answers

I would just put it very simply using a host folder instead of using any kind of named or un-named volume

docker run \
  -d \
  -p 3000:3000 \
  --name=grafana \
  -v /opt/grafana:/var/lib/grafana \
  grafana/grafana

What this will do is do is map the container directory "/var/lib/grafana/" to a directory "/opt/grafana" (change based on what suits you) on your docker server.

Docker volumes are good when we need to serve multiple containers using compose or use swarm deployments. In your case things can be kept simple.

like image 88
Tarun Lalwani Avatar answered Oct 13 '22 14:10

Tarun Lalwani


I would recommend the following solution:

$ docker volume create grafana-storage
grafana-storage

$ docker volume ls
DRIVER              VOLUME NAME              
local               grafana-storage

This is created in /var/lib/docker/volumes/grafana-storage on UNIX. Than you can start your grafana container and mount the content of /var/lib/grafana (from inside your container) to the grafana-storage which is a named docker volume.

Start your container

docker run -d -p 3000:3000 --name=grafana -v grafana-storage:/var/lib/grafana grafana/grafana

When you go to /var/lib/docker/volumes/grafana-storage/_data as root you can see your content. You can reuse this content (delete your grafana container: docker rm -f xxx) and start a new container. Use again -v grafana-storage:/var/lib/grafana.

The --volumes-from is an "old" method to achieve the same in an 'more ugly' way.

This command will create an empty volume in /var/lib/docker/volumes:

$ docker run -d -v /var/lib/grafana --name grafana-storage busybox:latest

Empty storage is here:

cd /var/lib/docker/volumes/6178f4831281df02b7cb851cb32d8025c20029f3015e9135468a374d13386c21/_data/

You start your grafana container:

docker run -d -p 3000:3000 --name=grafana --volumes-from grafana-storage grafana/grafana

The storage of /var/lib/grafana from inside your container will be stored inside /var/lib/docker/volumes/6178f4831281df02b7cb851cb32d8025c20029f3015e9135468a374d13386c21/_data/ which you've created by the busybox container. If you delete your grafana container, the data will remain there.

# cd /var/lib/docker/volumes/6178f4831281df02b7cb851cb32d8025c20029f3015e9135468a374d13386c21/_data/
# ls
grafana.db  plugins
like image 45
lvthillo Avatar answered Oct 13 '22 14:10

lvthillo