Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.
Grafana connects with every possible data source, commonly referred to as databases such as Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL etc. Grafana being an open source solution also enables us to write plugins from scratch for integration with several different data sources. The tool helps us study, analyse & monitor data over a period of time, technically called time series analytics.
In this guide we will learn how to run Grafana using docker and docker-compose.
Related content:
- How to Setup Promtail, Grafana and Loki for free Log Management in Debian 11
- How to install and set up Grafana in Ubuntu 20.04 using Ansible
- How to run Grafana Loki with docker and docker-compose
Ensure that docker and docker compose is installed
Since we will be using docker to run our set up, it is important that it is installed and running. Please ensure that you are have docker installed. If you are using an Ubuntu system, checkout this guide on How to Install and Use Docker in Ubuntu 22.04.
Confirm that docker is working as expecting by checking the version:
|
|
Next, ensure that docker-compose
is installed. Docker compose is available as a python pip package. Ensure that python and pip is installed then install docker-compose with this command:
|
|
This is the version of docker-compose installed in my system:
|
|
Running Grafana in docker
To run Grafana with docker, use the following command. We are running the latest version of Grafana OSS – version 9.
|
|
You can use the -d
argument to start in detached mode. Once the server is started, access it by visiting http://server_ip:3000
in your browser.
Install plugins in the Docker container
You can install official and community plugins listed on the Grafana plugins page or from a custom URL.
Install official and community Grafana plugins
Pass the plugins you want installed to Docker with the GF_INSTALL_PLUGINS
environment variable as a comma-separated list. This sends each plugin name to grafana-cli plugins install ${plugin}
and installs them when Grafana starts.
|
|
Note: If you need to specify the version of a plugin, then you can add it to the
GF_INSTALL_PLUGINS
environment variable. Otherwise, the latest is used. For example:-e "GF_INSTALL_PLUGINS=grafana-clock-panel 1.0.1,grafana-simple-json-datasource 1.3.5"
Save your Grafana data
If you do not designate a location for information storage, then all your Grafana data disappears as soon as you stop your container. To save your data, you need to set up persistent storage or bind mounts for your container.
Run Grafana container with persistent storage (recommended)
|
|
You may want to run Grafana in Docker but use folders on your host for the database or configuration. When doing so, it becomes important to start the container with a user that is able to access and write to the folder you map into the container.
|
|
Using Docker-compose to run Grafana
We can add the instructions above to a docker compose file to make it easy for us to create, update and manage the deployments. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Add the following to a docker-compose.yaml
file:
|
|
Save the file in the directory with the configurations then start the services with this command:
|
|
Or you can add the -d
argument for detached mode. Since we are binding the same ports, you can access in the same way as listed above.
Logging in to Grafana
Since we mounted the port to localhost:3000, head over to that url in your browser.
Login with your admin user (default admin
/admin
). You will be prompted to change your password the first time you login.
Conclusion
In this guide we managed to run Grafana using docker and docker-compose. You can now add data sources and create graphs.