In this article, we will show you how easy it is to set up Grafana on Linux (e.g. a Raspberry Pi). Grafana is an open source software to display data from a number of sources, e.g. a SQLite, MySQL or InfluxDB database. The data can then be presented in many different formats.
First, I suggest you check out the Tutorial to install Docker on Linux, if you have not done so yet. Important: Make sure that you follow the steps regarding adding a new docker user, otherwise you will have to execute every command as the root user using sudo.
Step 1: Setup persistent storage for Grafana in Docker
To avoid loosing the data in Grafana when stopping the Docker image, we setup a persistant storage:
docker volume create grafana-storage
Step 2: Download and run Grafana docker container
This is quite easy, since we already have Docker installed. We use the Alpine Linux based image. But for those who prefer Ubuntu, you can use the second command.
We pass the –volume option to make sure that Grafana uses the persistent storage we set up in step 1.
docker run -d -p 3000:3000 --name=grafana \
--volume grafana-storage:/var/lib/grafana grafana/grafana
Command for image with Ubuntu:
docker run -d -p 3000:3000 --name=grafana \
--volume grafana-storage:/var/lib/grafana grafana/grafana:7.1.1-ubuntu
Now we have Grafana running in a Docker image on port 3000, which is also mapped to the localhost port 3000. So if you have it running, you can enter http://localhost:3000 into your browser and see Grafana.
Step 3: Confirm that the image is running
To make sure that the image is running, we can execute:
docker ps
This should give an output similar to the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c4667637dc73 grafana/grafana "/run.sh" 10 seconds ago Up 7 seconds 0.0.0.0:3000->3000/tcp grafana
Step 4: Stopping and starting the container in the future
To stop the Grafana container, you can use the following command:
docker stop grafana
To start it again, you can use:
docker start grafana
Optional: Install plugins along with the container
If you already know that you will use certain plugins, you can use the following command to install these together with the container:
docker run -d -p 3000:3000 --name=grafana \
-e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" grafana/grafana
More details regarding further setup information can be found here:
https://grafana.com/docs/grafana/latest/installation/docker/#install-plugins-in-the-docker-container