Recover configuration of Grafana-docker persistent volume?

xCovelus picture xCovelus · Aug 17, 2017 · Viewed 7.9k times · Source

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.

Answer

lvthillo picture lvthillo · Aug 17, 2017

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