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


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
Service | URL |
Prometheus | http://localhost:9090 |
Grafana | http://localhost:3000 |
Nginx | http://localhost:8081 |
Apache (httpd) | http://localhost:8082 |
Redis CLI | docker exec -it app3 redis-cli |
π Visualize Metrics in Grafana
Open Grafana: http://localhost:3000
Default login:
admin
/admin
Add Prometheus as a data source (
http://prometheus:9090
)Import a dashboard (use ID
1860
for Node Exporter)π¨ Enjoy live graphs of your system + containers!
π Useful Links
Official Redis Docs
Node Exporter Grafana Dashboard ID 1860
β 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
Subscribe to my newsletter
Read articles from Dheeraj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
