$docker.recipes

Prometheus + Grafana

intermediate

Industry-standard monitoring stack with Prometheus metrics collection and Grafana visualization dashboards.

[i]Overview

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud in 2012, designed around a pull-based architecture that scrapes metrics from configured targets at given intervals. Unlike traditional push-based monitoring systems, Prometheus actively discovers and pulls metrics from services, storing them as time-series data with powerful labeling capabilities and querying them through PromQL (Prometheus Query Language). This approach makes it exceptionally well-suited for dynamic environments like Kubernetes clusters and microservices architectures. This monitoring stack combines Prometheus's robust metric collection and storage capabilities with Grafana's industry-leading visualization platform to create a comprehensive observability solution. Prometheus handles the heavy lifting of metric ingestion, storage, and alerting logic, while Grafana transforms that raw time-series data into meaningful dashboards, graphs, and visual analytics. The integration between these tools is particularly tight, with Grafana natively supporting PromQL queries and Prometheus providing the dimensional data model that Grafana excels at visualizing. DevOps teams, SRE professionals, and infrastructure engineers gravitate toward this combination because it offers enterprise-grade monitoring capabilities without vendor lock-in or licensing costs. The stack excels in cloud-native environments where traditional monitoring solutions struggle with ephemeral infrastructure and rapid deployment cycles. Organizations choosing this setup gain deep visibility into application performance, infrastructure health, and business metrics through a single pane of glass, while maintaining full control over their monitoring data and retention policies.

[*]Key Features

  • [+]Pull-based metrics collection with automatic service discovery for Kubernetes, Docker, and DNS
  • [+]PromQL query language for complex time-series analysis and aggregation across multiple dimensions
  • [+]Multi-dimensional data model using labels for flexible metric organization and filtering
  • [+]Grafana's 50+ data source integrations beyond Prometheus including InfluxDB, Elasticsearch, and cloud providers
  • [+]Rich visualization library with graphs, heatmaps, stat panels, and geographical maps
  • [+]Built-in alerting with Prometheus Alertmanager and Grafana's notification channels
  • [+]Dashboard templating with variables for dynamic, reusable monitoring views
  • [+]15-day metric retention configured with TSDB storage optimization

[#]Common Use Cases

  • [1]Kubernetes cluster monitoring with pod, node, and application-level metrics visibility
  • [2]Microservices observability tracking request rates, error rates, and latency across service boundaries
  • [3]Infrastructure monitoring for servers, databases, and network equipment using various exporters
  • [4]Application performance monitoring with custom business metrics and SLI/SLO tracking
  • [5]DevOps pipeline monitoring including build times, deployment frequency, and failure rates
  • [6]IoT and sensor data visualization for time-series environmental or industrial monitoring
  • [7]Cost optimization dashboards tracking cloud resource usage and spending patterns

[!]Prerequisites

  • [!]Minimum 1.5GB RAM total (1GB for Prometheus, 512MB for Grafana) for basic monitoring workloads
  • [!]Docker and Docker Compose installed with sufficient storage for time-series data retention
  • [!]Network access to target systems you want to monitor on their metrics endpoints
  • [!]Basic understanding of time-series data concepts and metric types (counters, gauges, histograms)
  • [!]Prometheus configuration file (prometheus.yml) with scrape targets defined for your environment
  • [!]GRAFANA_USER and GRAFANA_PASSWORD environment variables set for initial admin access
[!]

WARNING: For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

[$]docker-compose.yml

[docker-compose.yml]
1services:
2 prometheus:
3 image: prom/prometheus:latest
4 container_name: prometheus
5 restart: unless-stopped
6 command:
7 - '--config.file=/etc/prometheus/prometheus.yml'
8 - '--storage.tsdb.path=/prometheus'
9 - '--storage.tsdb.retention.time=15d'
10 - '--web.enable-lifecycle'
11 volumes:
12 - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
13 - prometheus_data:/prometheus
14 ports:
15 - "9090:9090"
16 networks:
17 - monitoring
18
19 grafana:
20 image: grafana/grafana:latest
21 container_name: grafana
22 restart: unless-stopped
23 environment:
24 GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}
25 GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
26 GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel
27 volumes:
28 - grafana_data:/var/lib/grafana
29 ports:
30 - "3000:3000"
31 depends_on:
32 - prometheus
33 networks:
34 - monitoring
35
36volumes:
37 prometheus_data:
38 grafana_data:
39
40networks:
41 monitoring:
42 driver: bridge

[$].env Template

[.env]
1# Grafana Configuration
2GRAFANA_USER=admin
3GRAFANA_PASSWORD=changeme

[i]Usage Notes

  1. [1]Docs: https://prometheus.io/docs/ and https://grafana.com/docs/
  2. [2]Grafana at http://localhost:3000 (admin/GRAFANA_PASSWORD)
  3. [3]Prometheus at http://localhost:9090 - query interface and target status
  4. [4]Create prometheus/prometheus.yml with scrape_configs for your services
  5. [5]Add Prometheus data source in Grafana: http://prometheus:9090
  6. [6]Import dashboards from https://grafana.com/grafana/dashboards/

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

prometheus
prometheus:
  image: prom/prometheus:latest
  container_name: prometheus
  restart: unless-stopped
  command:
    - "--config.file=/etc/prometheus/prometheus.yml"
    - "--storage.tsdb.path=/prometheus"
    - "--storage.tsdb.retention.time=15d"
    - "--web.enable-lifecycle"
  volumes:
    - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    - prometheus_data:/prometheus
  ports:
    - "9090:9090"
  networks:
    - monitoring
grafana
grafana:
  image: grafana/grafana:latest
  container_name: grafana
  restart: unless-stopped
  environment:
    GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}
    GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
    GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel
  volumes:
    - grafana_data:/var/lib/grafana
  ports:
    - "3000:3000"
  depends_on:
    - prometheus
  networks:
    - monitoring

[>]Quick Start

[terminal]
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 prometheus:
5 image: prom/prometheus:latest
6 container_name: prometheus
7 restart: unless-stopped
8 command:
9 - '--config.file=/etc/prometheus/prometheus.yml'
10 - '--storage.tsdb.path=/prometheus'
11 - '--storage.tsdb.retention.time=15d'
12 - '--web.enable-lifecycle'
13 volumes:
14 - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
15 - prometheus_data:/prometheus
16 ports:
17 - "9090:9090"
18 networks:
19 - monitoring
20
21 grafana:
22 image: grafana/grafana:latest
23 container_name: grafana
24 restart: unless-stopped
25 environment:
26 GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}
27 GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
28 GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel
29 volumes:
30 - grafana_data:/var/lib/grafana
31 ports:
32 - "3000:3000"
33 depends_on:
34 - prometheus
35 networks:
36 - monitoring
37
38volumes:
39 prometheus_data:
40 grafana_data:
41
42networks:
43 monitoring:
44 driver: bridge
45EOF
46
47# 2. Create the .env file
48cat > .env << 'EOF'
49# Grafana Configuration
50GRAFANA_USER=admin
51GRAFANA_PASSWORD=changeme
52EOF
53
54# 3. Start the services
55docker compose up -d
56
57# 4. View logs
58docker compose logs -f

[>]One-Liner

Run this command to download and set up the recipe in one step:

[terminal]
1curl -fsSL https://docker.recipes/api/recipes/prometheus-grafana/run | bash

[?]Troubleshooting

  • [!]Prometheus targets showing as 'DOWN': Verify network connectivity and that target applications expose metrics on configured ports
  • [!]Grafana shows 'No data points' error: Check Prometheus data source configuration uses http://prometheus:9090 URL within Docker network
  • [!]High memory usage in Prometheus: Reduce metric retention time or increase scrape intervals in prometheus.yml configuration
  • [!]PromQL queries timing out: Optimize query complexity, reduce time ranges, or increase Prometheus query timeout settings
  • [!]Grafana dashboards not persisting: Ensure grafana_data volume is properly mounted and container has write permissions
  • [!]Missing metrics from exporters: Verify exporter compatibility with Prometheus version and check scrape_configs job names match targets

Community Notes

Loading...
Loading notes...

## Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license