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 Overflow
🌐
Grafana
grafana.com › docs › grafana › latest › setup-grafana › installation › docker
Run Grafana Docker image | Grafana documentation
Now, add the following code into the docker-compose.yaml file. ... services: grafana: image: grafana/grafana-enterprise container_name: grafana restart: unless-stopped # if you are running as root then set it to 0 # else find the right id with the id -u command user: '0' ports: - '3000:3000' # adding the mount volume point which we create earlier volumes: - '$PWD/data:/var/lib/grafana'
🌐
Grafana
grafana.com › docs › grafana › latest › setup-grafana › configure-docker
Configure a Grafana Docker image | Grafana documentation
To increase the log level to DEBUG mode, add the environment variable GF_LOG_LEVEL to the docker-compose.yaml file. ... version: '3.8' services: grafana: image: grafana/grafana-enterprise container_name: grafana restart: unless-stopped environment: # increases the log level from info to debug - GF_LOG_LEVEL=debug ports: - '3000:3000' volumes: - 'grafana_storage:/var/lib/grafana' volumes: grafana_storage: {}
Discussions

Running Grafana as Docker, but doesn't remember my changes if I restart the container
You need persistent storage for your containerized grafana configuration. More on reddit.com
🌐 r/docker
28
16
January 24, 2021
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
I have created a grafana docker image in aws fargate using aws ecs. The web app works well. However, I loose dashboards and user information anytime I restart the app. From my readings, this is bec... More on stackoverflow.com
🌐 stackoverflow.com
Recover configuration of Grafana-docker persistent volume? - Stack Overflow
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 More on stackoverflow.com
🌐 stackoverflow.com
Docker volume mount
Hello Team, I have recently did mount my docker volume at outside the container (on host machine) path /var/lib/grafana (same like container). Now I try to restore it with newer image with following cmd → docker run -d --name=grafana --restart=always -v /var/lib/grafana:/var/lib/grafana ... More on community.grafana.com
🌐 community.grafana.com
1
0
August 1, 2023
🌐
Medium
medium.com › cloudnloud › run-the-docker-image-for-grafana-33e8fad8fd6d
Run the Docker image for Grafana | by Shyju krishnan | Cloudnloud Tech Community | Medium
July 2, 2023 - Verify the volume was created correctly. ... Start the Grafana container by running the following command. docker run -d -p 3000:3000 --name=grafana \ --volume grafana-storage:/var/lib/grafana \ grafana/grafana-enterprise
🌐
Reddit
reddit.com › r/docker › running grafana as docker, but doesn't remember my changes if i restart the container
r/docker on Reddit: Running Grafana as Docker, but doesn't remember my changes if I restart the container
January 24, 2021 -

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

🌐
Medium
medium.com › @syed_usman_ahmed › using-grafana-with-docker-part-2-85883d833867
Deploy Grafana latest version with Docker — Part 2 | by Syed Usman Ahmad | Medium
October 28, 2024 - docker run -d -p 3000:3000 --name grafana --volume grafana-storage:/var/lib/grafana grafana/grafana-oss:latestdocker run -d -p 3000:3000 --name grafana --volume grafana-storage:/var/lib/grafana grafana/grafana-oss:latest
🌐
Stack Overflow
stackoverflow.com › questions › 73239176 › how-to-create-and-mount-a-volume-to-a-grafana-docker-image-and-use-it-to-strore
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
Hello Onecricketeer, thank you for the shared link, I will try it, but do you know how I can do it using the dockerfile ? ... You cant. You need to mount the volume at runtime ... @OneCricketeer, I tried you solution but it does not work. I still loose the user information and dashboards when I stop the container ... Save this answer. Show activity on this post. Instead of making container have persistent storage one alternative could be to have a custom entrypoint script that downloads the dashboards and put them in /etc/grafana/provisioning/dashboards/ (could be from s3) and then runs /run.sh this way you can keep your container stateless and not add any storage to it.
Find elsewhere
Top answer
1 of 2
14

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
2 of 2
12

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.

🌐
How-To Geek
howtogeek.com › home › cloud › how to run grafana in a docker container
How to Run Grafana In a Docker Container
March 19, 2022 - This example starts a new Grafana ... as this is Grafana's default listening address. A Docker volume called grafana-data is referenced by the -v flag....
🌐
Grafana
community.grafana.com › configuration
Docker volume mount - Configuration - Grafana Labs Community Forums
August 1, 2023 - Hello Team, I have recently did ... restore it with newer image with following cmd → docker run -d --name=grafana --restart=always -v /var/lib/grafana:/var/lib/grafana ......
🌐
Grafana
community.grafana.com › installation
Grafana 10 docker installation, with mounted volume - Installation - Grafana Labs Community Forums
June 21, 2023 - Hi, This is the first time I install Grafana, I’m not a linux expert, just trying to learn making myself a home lab, so the problem is that I’ve installed Truenas, then i created a dataset which I’m mounting in the host where I run docker, I’m using the following docker compose to install Grafana latest version: version: '3' networks: spider: external: true services: grafana_changarritos: container_name: grafana_changarritos image: grafana/grafana:latest restart: always ...
🌐
Grafana
community.grafana.com › configuration
Docker volumes and plugins - Configuration - Grafana Labs Community Forums
June 21, 2018 - When installing a plugin from Dockerfile it works until I use a volume. In this case, the target /var/lib/grafana directory is mapped on a docker source volume: the target overrides the plugin directory and the install…
🌐
Huihoo
docs.huihoo.com › grafana › 2.6 › installation › docker › index.html
Installing on Docker - Grafana Documentation
You can map these volumes to host folders when you start the container: $ docker run -d -p 3000:3000 \ -v /var/lib/grafana:/var/lib/grafana \ -e "GF_SECURITY_ADMIN_PASSWORD=secret" \ grafana/grafana:develop
🌐
Earthly
earthly.dev › blog › running-grafana-in-docker
Make It Observable: Running Grafana in Docker - Earthly Blog
July 19, 2023 - docker run -d --name=sample_grafana -v \ grafana-storage:/var/lib/grafana -p 3000:3000 grafana/grafana · Here, a persistent volume called grafana-storage is created and mounted on the /var/lib/grafana directory, where Grafana stores all its generated data and plugins.
🌐
Grafana
community.grafana.com › t › what-volumes-should-i-mount-when-using-docker › 42445
What volumes should I mount when using Docker? - Grafana - Grafana Labs Community Forums
January 31, 2021 - First of all, the documentation I’m reading for Docker setup is really really bad: Run Grafana Docker image | Grafana Labs Docker | Grafana Labs Basically there’s VERY little mention of how to set up the bind mounts / volume mounts for data persistence here.
Top answer
1 of 2
3

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.

2 of 2
0

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
🌐
Last9
last9.io › blog › grafana-and-docker
Grafana and Docker: Setup, Configure, and Monitor (2026) | Last9
3 weeks ago - How do I ensure data persistence for Grafana in Docker? To ensure data persistence, mount Docker volumes to store Grafana’s configuration and data outside the container.
🌐
Reddit
reddit.com › r/grafana › how to mount and map a volume to an already existing container?
r/grafana on Reddit: How to mount and map a volume to an already existing container?
September 5, 2023 -

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.

🌐
Grafana
community.grafana.com › configuration
Grafana Docker and data persistence - Configuration - Grafana Labs Community Forums
July 15, 2020 - Hello all, I am trying to get my Grafana docker container to persist data. I’ve configured the container to run as root to rule out any user account related issues. I’m not sure what I’m doing wrong but I can’t get the …
🌐
Medium
medium.com › @whaleberry › docker-volume-with-amazon-ecs-c0cc830d2362
Stateful Grafana with Docker Volume on Amazon ECS | by Olawale Olaleye | Medium
May 2, 2023 - root@ip-192-168-119-212 ~]# ls -lrt /var/lib/docker/volumes/grafana/_data total 1024 drwxrwxrwx 4 472 root 71 Dec 2 10:57 plugins drwxr-x--- 2 472 root 6 Dec 2 10:57 file-collections drwx------ 2 472 root 6 Dec 2 10:57 png drwx------ 2 472 root 6 Dec 2 10:57 csv drwxr-x--- 3 472 root 15 Dec 2 10:57 alerting -rw-r----- 1 472 root 909312 Dec 2 10:57 grafana.db