Join our Discord Server
Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Run And Configure Grafana Docker Image

5 min read

Grafana provides a comprehensive solution for data visualization, exploration, and monitoring, helping organizations make better decisions by providing them with a clear understanding of their data. It is an open-source data visualization and monitoring platform. It provides a powerful and flexible way to visualize and analyze data from various sources such as databases, log files, cloud services, and more.

What problems does Grafana solve?

Grafana solves the problem of data discovery and analysis, enabling users to explore and make sense of their data in a meaningful way. It does this by providing an intuitive and user-friendly interface for building visualizations and dashboards, making it easy to quickly identify trends, patterns, and insights within large amounts of data.

Grafana integrates with a variety of data sources, allowing users to centralize their data into a single platform, and provides robust alerting and notification capabilities, enabling users to be notified of critical changes to their data in real-time.

To run the Grafana Docker image, you can use the following command:

docker run -d -p 3000:3000 grafana/grafana

This command will download the latest Grafana Docker image from Docker Hub and run it in the background, mapping port 3000 on the host to port 3000 in the container.

Using Environment Variable

To configure the Grafana Docker image, you can either pass configuration options as environment variables or mount a configuration file as a volume.

Here’s an example of using environment variables:

docker run -d -p 3000:3000 \
  -e "GF_USERS_ALLOW_SIGN_UP=false" \

Mounting a Configuration File

Here’s an example of mounting a configuration file:

docker run -d -p 3000:3000 \
  -v /path/to/grafana.ini:/etc/grafana/grafana.ini \

Adding MongoDB Plugin

To add the MongoDB plugin to the Grafana Docker image, you can use the following command:

docker exec -it grafana grafana-cli plugins install grafana-mongodb-datasource

This command will run the grafana-cli tool inside the running Grafana container, and install the grafana-mongodb-datasource plugin. After the plugin is installed, you need to restart the Grafana container for the changes to take effect.

Adding Redis Data Source for Grafana Plugin

The Redis Data Source for Grafana is a plug-in that allows users to connect to the Redis database and build dashboards in Grafana to easily monitor Redis and application data. It provides an out-of-the-box predefined dashboard, but also lets you build customized dashboards tuned to your specific needs.

my image

Features and Capabilities

  • Grafana 7.1 and later with a new plug-in platform supported.
  • Data Source can connect to any Redis database. No special configuration is required.
  • Redis Cluster and Sentinel supported since version 1.2.
  • Data Source supports:

You can install and run Grafana using the official Docker image.

Step 1. Install Docker

The first step is to install docker for your operating system. Run the docker version command in a terminal window to make sure that docker is installed correctly.


On Windows and Mac, install docker version 18.03 or higher. You can run docker version to find out your docker version.

Step 2. Run Grafana Docker container

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. In our case, we will be using redis-datasource.

 docker run -d -p 3000:3000 --name=grafana -e "GF_INSTALL_PLUGINS=redis-datasource" grafana/grafana

Step 3. Accessing the grafana dashboard

Open https://IP:3000 to access grafana. The default username/password is admin/admin.


Step 4. Click “Configuration”


Step 5. Add Redis as a Data Source


Step 6. Select “Redis” as data source type


Step 7. Add Redis Database name, Endpoint URL and password

Assuming that you already have Redis server and database up and running in your infrastructure. You can also leverage Redis Enterprise Cloud as showcased in the below example.


Step 8. Click “Import” under Dashboard


Step 9.Access the Redis datasource Dashboard


Grafana and Prometheus working together

Grafana and Prometheus are commonly used together as part of a monitoring stack, with Prometheus providing the data storage and collection and Grafana providing the visualization and analysis layer.

Here are the steps to use Grafana with Prometheus:

Deploy Prometheus:

You can either install Prometheus on your own servers or use a hosted service.

Configure Prometheus data source:

Once Prometheus is up and running, log in to Grafana and go to the “Data Sources” section. From there, click on “Add data source” and select “Prometheus” as the type. Fill in the details of your Prometheus installation, including the URL and any authentication information, and then click “Save & Test”.

Create a dashboard:

Next, create a new dashboard by clicking on the “Create dashboard” button in the Grafana UI. This will open up the Grafana panel editor, where you can add different visualizations and panels to represent your data.

Add visualizations:

To add a visualization, click on the “Add Panel” button in the Grafana UI and select the type of visualization you want to create. For example, you could create a line chart to show the evolution of a metric over time.

Query Prometheus data:

To query data from Prometheus, use the Prometheus query language (PromQL) in the Grafana panel editor. You can enter a PromQL expression to retrieve the data you want to visualize.

Customize the dashboard:

Once you have added visualizations to your dashboard, you can further customize it by adjusting the display options, such as the axis labels, grid lines, and color palette.

Save and share:

Finally, save your dashboard by clicking on the “Save” button in the Grafana UI. You can then share your dashboard with others by providing them with the URL.

By using Grafana with Prometheus, you can easily visualize and analyze the data collected by Prometheus, and make better decisions based on that data.

Here’s an example of a docker-compose.yml file that brings up both Grafana and Prometheus together:

version: '3'
    image: prom/prometheus
      - 9090:9090
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    image: grafana/grafana
      - 3000:3000
      - grafana-data:/var/lib/grafana
      GF_USERS_ALLOW_SIGN_UP: 'false'

In this example, the Prometheus service is using the official Prometheus Docker image and exposing port 9090 on the host to port 9090 in the container. The Prometheus configuration file is mounted as a volume.

The Grafana service is using the official Grafana Docker image and exposing port 3000 on the host to port 3000 in the container. The Grafana data is persisted in a named volume grafana-data. Additionally, the GF_SECURITY_ADMIN_PASSWORD environment variable is set to secret, and sign-up is disabled by setting GF_USERS_ALLOW_SIGN_UP to false.

To bring up the stack, simply run the following command in the same directory as the docker-compose.yml file:

docker-compose up -d

This will download the required images, create the named volume, and start the containers in the background. You can then access Grafana at http://localhost:3000, and Prometheus at http://localhost:9090.

To add Prometheus as a data source in Grafana, log in to the Grafana UI, go to the “Data Sources” section, and add a new data source of type “Prometheus”. Fill in the URL of your Prometheus instance, which in this case would be http://prometheus:9090, and save the changes.

With this docker-compose.yml file, you now have a fully functional monitoring stack, with Prometheus providing the data collection and storage, and Grafana providing the visualization and analysis layer.

Using Grafana with Loki

Here’s a sample docker-compose.yml file that you can use to set up Grafana and Loki with Docker:

version: '3'
    image: grafana/grafana
      - "3000:3000"
      GF_INSTALL_PLUGINS: grafana-piechart-panel,grafana-loki-datasource
      - grafana-data:/var/lib/grafana
    image: grafana/loki
      - "3100:3100"
      - loki-data:/loki/data

In this example, we’re using the official Grafana and Loki Docker images and exposing ports 3000 and 3100, respectively, so that you can access the Grafana and Loki web interfaces.

Additionally, we’re installing the grafana-piechart-panel and grafana-loki-datasource plugins in Grafana, which provide useful functionality for visualizing data.

We’re also defining two volumes, grafana-data and loki-data, to persist the data generated by Grafana and Loki.

To start the services, run the following command in the same directory as the docker-compose.yml file:

docker-compose up -d

This will download the images if they’re not already available locally and start the services in the background. You can access Grafana in your web browser at http://localhost:3000, and Loki at http://localhost:3100.

Please follow and like us:

Have Queries? Join

Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Exploring the Cloud-Native Ecosystem: A Beginner’s Guide to the…

The Cloud Native Computing Foundation (CNCF) is a non-profit organization founded in 2015 with the goal of advancing the development and adoption of cloud-native technologies. The...
Ajeet Raina
3 min read
Join our Discord Server