Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Run Grafana and Prometheus in Docker and Build a Dashboard

Run Grafana and Prometheus on a shared Docker network, keep dashboard data in a volume, and plot a working Prometheus metric.

Table of Contents

This setup runs Grafana and Prometheus in Docker on one computer. Prometheus collects its own metrics so you can test the whole connection before adding another target. You’ll need a working Docker installation. If you’re new to volumes and networks, use the TipsMake Docker learning path as a reference.

Run Grafana with persistent storage

Create a network for the two containers and a volume for Grafana’s settings and dashboards. Then pull Grafana and start it. The examples assume you can run Docker as your current user. Use your platform’s normal Docker permissions if you receive a permission error.

docker network create monitoring
docker volume create grafana-data
docker pull grafana/grafana

How to Install and Use Grafana for Real-Time Data Visualization Picture 1

docker run -d --name grafana --network monitoring 
  -p 127.0.0.1:3000:3000 
  -v grafana-data:/var/lib/grafana 
  grafana/grafana

How to Install and Use Grafana for Real-Time Data Visualization Picture 2

Open http://127.0.0.1:3000 on the Docker host. Sign in with the initial username admin and password admin, then set a new password when prompted. The screenshots show an earlier version of the interface.

How to Install and Use Grafana for Real-Time Data Visualization Picture 3

How to Install and Use Grafana for Real-Time Data Visualization Picture 4

How to Install and Use Grafana for Real-Time Data Visualization Picture 5

Start Prometheus and verify it has a target

Next, create a separate volume for Prometheus data. The image’s bundled example configuration scrapes Prometheus itself. This creates a working target without installing a system exporter.

docker volume create prometheus-data
docker pull prom/prometheus

How to Install and Use Grafana for Real-Time Data Visualization Picture 6

docker run -d --name prometheus --network monitoring 
  -p 127.0.0.1:9090:9090 
  -v prometheus-data:/prometheus 
  prom/prometheus

How to Install and Use Grafana for Real-Time Data Visualization Picture 7

On the Docker host, open http://127.0.0.1:9090 and run the query up after the first scrape. A result of 1 means Prometheus reached the target.

Connect Grafana to Prometheus

In Grafana, open Connections > Add new connection, choose Prometheus, and add it as a data source.

How to Install and Use Grafana for Real-Time Data Visualization Picture 8

Use http://prometheus:9090 as the server URL, then select Save & test. The service name resolves on the shared Docker network. If you enter localhost here, Grafana looks inside its own container. The multi-container networking tutorial explains the difference.

How to Install and Use Grafana for Real-Time Data Visualization Picture 9

Build your first dashboard panel

Open Dashboards > New > New dashboard.

How to Install and Use Grafana for Real-Time Data Visualization Picture 10

Select Add visualization and choose your Prometheus data source.

How to Install and Use Grafana for Real-Time Data Visualization Picture 11

How to Install and Use Grafana for Real-Time Data Visualization Picture 12

Enter rate(process_cpu_seconds_total[5m]) in the PromQL editor, run the query, and save the panel and dashboard. It shows how many CPU seconds the Prometheus process used per second over the selected period. If it shows no data immediately, test up and give Prometheus time to collect more samples.

How to Install and Use Grafana for Real-Time Data Visualization Picture 13

Import a dashboard or add host metrics

In the dashboard import screen, enter an ID from the Grafana dashboard catalog and map it to your data source. Community dashboards may rely on metrics from a particular exporter. For host CPU, memory, and filesystem metrics, configure an appropriate exporter and add it as a target using the Prometheus setup guide.

How to Install and Use Grafana for Real-Time Data Visualization Picture 14

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.