# Install Grafana with Docker and Build Your First Dashboard

> Run Grafana in a container with a persistent volume, connect Prometheus as a data source, provision it from files and build your first dashboard step by step.

- Source: https://www.itwonderlab.com/install-grafana-docker/
- Published: 2026-08-08
- Updated: 2026-08-08
- Author: Javier Ruiz Jiménez (https://www.javierruizjimenez.com/)
- Site: IT Wonder Lab (https://www.itwonderlab.com/)

---

## What is Grafana

[Grafana](https://www.itwonderlab.com/grafana/) is an open source platform that turns metrics, logs and traces into dashboards and alerts. It does not store metrics itself: it queries **data sources** such as [Prometheus](https://www.itwonderlab.com/prometheus/) or Amazon CloudWatch. In this tutorial you run Grafana in a container, keep its data in a volume, add Prometheus as a data source and create a dashboard.

You need [Docker](https://www.itwonderlab.com/docker/) or [Rancher Desktop](https://www.itwonderlab.com/rancher-desktop/) running. If you have no Prometheus yet, follow [Install Prometheus with Docker](https://www.itwonderlab.com/install-prometheus-docker/) first, or use the Compose file below, which starts both.

## Run Grafana with one command

```bash
docker volume create grafana-data
docker run -d --name grafana -p 3000:3000 -v grafana-data:/var/lib/grafana grafana/grafana-oss
```

Open `http://localhost:3000`. The first user is `admin` with the password `admin`, and Grafana asks you to change it. The volume keeps dashboards, users and settings when you recreate the container.

## Grafana and Prometheus with Docker Compose

A Compose file is easier to repeat. This one starts Prometheus and Grafana on the same network, so Grafana reaches Prometheus by the name `prometheus`.

```yaml title="compose.yaml"
services:
  prometheus:
    image: prom/prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
    ports:
      - "9090:9090"
  grafana:
    image: grafana/grafana-oss
    ports:
      - "3000:3000"
    volumes:
      - grafana-data:/var/lib/grafana
      - ./provisioning:/etc/grafana/provisioning:ro
    depends_on:
      - prometheus
volumes:
  grafana-data:
```

```yaml title="prometheus.yml"
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["localhost:9090"]
```

## Provision the data source from a file

Provisioning creates the data source when Grafana starts, so nobody has to click through the UI and the setup is stored in Git.

```yaml title="provisioning/datasources/prometheus.yaml"
apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true
```

Start everything:

```bash
docker compose up -d
```

In Grafana, open **Connections > Data sources**: Prometheus is already there. Click **Save & test** and you should see "Successfully queried the Prometheus API".

## Create the first dashboard

1. Click **Dashboards > New > New dashboard > Add visualization** and select the Prometheus data source.
2. In the query box type `rate(prometheus_http_requests_total[5m])`.
3. Choose the **Time series** visualization, give the panel a title and click **Apply**.
4. Save the dashboard with **Save dashboard**.

Instead of building everything by hand, import a community dashboard: **Dashboards > New > Import**, type an ID from grafana.com/grafana/dashboards, for example `1860` (Node Exporter Full), and select your data source.

## Alerts

Grafana alerting evaluates a query on a schedule. Open **Alerting > Alert rules > New alert rule**, write a query such as `up == 0`, set a threshold and choose a contact point (email, Slack, a webhook). Group related rules in a folder.

## Next steps

- Back up the `grafana-data` volume, or store dashboards as JSON in Git and provision them with a `dashboards` provider.
- Use Grafana to watch a service mesh: see [Istio in a local Kubernetes cluster](https://www.itwonderlab.com/istio-in-local-kubernetes/).
- Deploy Prometheus and Grafana to a cluster with the [Terraform Helm provider](https://www.itwonderlab.com/terraform-helm-provider-kubernetes/).
