πŸš€ Building a Local Monitoring Stack with Docker: Prometheus, Grafana, and Redis

DheerajDheeraj
3 min read

Mini project

A hands-on mini project to monitor real services locally using Docker. Whether you're new to DevOps or brushing up your observability skills β€” this one's for you!


🧠 What We're Building

We're going to set up a complete monitoring stack on our local machine using Docker Desktop, which includes:

  • Prometheus: For scraping and storing metrics

  • Node Exporter: For collecting system metrics

  • Grafana: For visualizing metrics beautifully

  • Redis: A popular in-memory datastore to simulate an app

  • Nginx & Apache (httpd): Lightweight web servers to simulate services


🧰 Prerequisites

Before we begin, make sure you have:

  • Docker Desktop installed and running

  • Basic familiarity with Docker & containers

  • A code editor like VS Code


πŸ“ Project Directory Structure

Here’s what your project folder will look like:

bashCopyEditdocker-monitoring/
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ prometheus/
β”‚   └── prometheus.yml
└── README.md

πŸ›  Step-by-Step Setup

1️⃣ Create a Project Folder

mkdir docker-monitoring && cd docker-monitoring
mkdir prometheus

2️⃣ Write the prometheus.yml File

Inside the prometheus/ folder, create prometheus.yml:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['prometheus:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets: ['node-exporter:9100']

This tells Prometheus to:

  • Scrape its own metrics

  • Scrape metrics from the Node Exporter


3️⃣ Write the docker-compose.yml File

In the root folder, create docker-compose.yml:

version: '3.8'

services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - "3000:3000"

  node-exporter:
    image: prom/node-exporter
    container_name: node-exporter
    ports:
      - "9100:9100"

  app1:
    image: nginx
    container_name: app1
    ports:
      - "8081:80"

  app2:
    image: httpd
    container_name: app2
    ports:
      - "8082:80"

  app3:
    image: redis
    container_name: app3
    ports:
      - "6379:6379"

This sets up all containers β€” monitoring tools and mock services.


4️⃣ Launch the Stack

In your terminal, run:

docker-compose up -d

πŸŽ‰ Boom! All your services are now running as containers.


πŸ‘€ Accessing the Stack

ServiceURL
Prometheushttp://localhost:9090
Grafanahttp://localhost:3000
Nginxhttp://localhost:8081
Apache (httpd)http://localhost:8082
Redis CLIdocker exec -it app3 redis-cli

πŸ“Š Visualize Metrics in Grafana

  1. Open Grafana: http://localhost:3000

  2. Default login: admin / admin

  3. Add Prometheus as a data source (http://prometheus:9090)

  4. Import a dashboard (use ID 1860 for Node Exporter)

  5. 🎨 Enjoy live graphs of your system + containers!



βœ… Summary

In just a few steps, you:

  • Deployed Prometheus, Grafana, Node Exporter, Redis, Nginx & Apache using Docker

  • Monitored system and container metrics

  • Visualized everything in Grafana

0
Subscribe to my newsletter

Read articles from Dheeraj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dheeraj
Dheeraj