Recover configuration of Grafana-docker persistent volume?
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
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.