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.
Then 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. Reuse -v grafana-storage:/var/lib/grafana.
The --volumes-from is an "old" method to achieve the same in a '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
Answer from lvthillo on Stack OverflowRunning Grafana as Docker, but doesn't remember my changes if I restart the container
dockerfile - How to create and mount a volume to a grafana docker image and use it to strore grafana dashbords and user information - Stack Overflow
Recover configuration of Grafana-docker persistent volume? - Stack Overflow
Docker volume mount
Hello,
I'm running Grafana as a Docker using:
https://devconnected.com/how-to-install-influxdb-telegraf-and-grafana-on-docker/
I'm new to Docker, but I go into Grafana and setup a datasource and simple dashboard and all is ok, but if I restart the VM the container runs on or restart the docker contain instance it's as if I have just set it up as all changes are gone.
What do I need to do to save my changes?
Thanks
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.
Then 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. Reuse -v grafana-storage:/var/lib/grafana.
The --volumes-from is an "old" method to achieve the same in a '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.
It looks like there are some problems with the volume configuration in your Grafana container:
First, I think this was simply a typo in your question:
- grafana_ini:/etc/grafana/grafana.inianticipated location in container
I suspect that you were actually intending this:
- grafana_ini:/etc/grafana/grafana.ini
Which doesn't make any sense: grafana.ini is a file, but a volume is
a directory. Docker won't allow you to mount a directory on top of a
file, hence the error:
ERROR: .../etc/grafana/grafana.ini is not directory
You have the same problem with the grafana_data volume, which you're
attempting to mount on top of datasource.yml:
- grafana_data:/etc/grafana/provisioning/datasources/datasource.yml
I think you may be approaching this configuration in the wrong way; you may want to read through these documents:
- https://grafana.com/docs/grafana/latest/installation/docker/
- https://grafana.com/docs/grafana/latest/administration/configure-docker/
- https://grafana.com/docs/grafana/latest/administration/provisioning/
It is possible to configure Grafana (and Prometheus!) using only bind mounts and environment variables (this includes installing plugin, data sources, and dashboards), so you don't need to build your own custom images.
Unrelated to this particular problem, there are some other things in
your docker-compose.yml that are worth changing. You should no
longer be using the links directive...
links:
- prometheus
...because Docker maintains DNS for you automatically; your containers can refer to each other by name with no additional configuration.
Another problem that can cause a similar error, is when mixing up the file name extensions. Be mindful to not refer to them as .yaml in the docker-compose.yml file, when you've actually used .yml. Or vice versa.
For example, you have the following file:
grafana_datasources.yml
Then don't do (.yaml):
./evidently_service/config/grafana_datasources.yaml:/etc/grafana/provisioning/datasources/grafana_datasources.yaml
Do this instead (.yml):
./evidently_service/config/grafana_datasources.yml:/etc/grafana/provisioning/datasources/grafana_datasources.yml
How to mount and map a volume to an already existing container?
I have recently configured Grafana dashboards in my company and used docker for installation of Grafana.
Now I want to send alerts from Grafana, and I believe I have to make a few changes in the /etc/grafana/grafana.ini file in the SMTP section in order to send/receive mails. But this grafana.ini file is present in docker container and I'm not able to edit it by logging into the container due to permission issue.
I want to know if there's a way to map the grafana.ini file to my local server, so that I can make the necessary changes on it.