Monitoring your infrastructure shouldn't be complicated. In this guide, I'll show you how to spin up a complete monitoring solution with Prometheus and Grafana in just a few commands using Docker Compose.
What You'll Get
By the end of this tutorial, you'll have:
- Prometheus for metrics collection and storage
- Grafana for beautiful dashboards and visualization
- Node Exporter for system metrics (CPU, memory, disk)
- Nginx with its own exporter for web server monitoring
- Everything containerized and easy to manage
Prerequisites
You'll need:
- Docker and Docker Compose installed
- Basic understanding of containers
- 5 minutes of your time
Architecture Overview
Our stack consists of 5 services working together:
┌─────────────┐
│ Grafana │ (Port 3000)
│ Dashboard │
└──────┬──────┘
│ Queries
↓
┌─────────────┐ ┌──────────────┐
│ Prometheus │◄─────┤ Node Exporter│ (System Metrics)
│ (Port │ └──────────────┘
│ 9090) │
└──────┬──────┘ ┌──────────────┐
└─────────────┤Nginx Exporter│ (Web Metrics)
└──────┬───────┘
↓
┌──────────────┐
│ Nginx │ (Port 8080)
└──────────────┘
Quick Start
1. Clone the Repository
https://github.com/durrello/prometheus-grafana-docker.git
cd prometheus-grafana-docker
2. Start Everything
docker-compose up -d
That's it! Your monitoring stack is now running.
Accessing Your Services
Once everything is up, you can access:
| Service | URL | Credentials |
|---|---|---|
| Grafana | http://localhost:3000 | admin / admin |
| Prometheus | http://localhost:9090 | - |
| Node Exporter | http://localhost:9100/metrics | - |
| Nginx | http://localhost:8080 | - |
| Nginx Exporter | http://localhost:9113/metrics | - |
Setting Up Your First Dashboard
Step 1: Add Prometheus as a Data Source
- Log into Grafana (http://localhost:3000)
- Go to Configuration → Data Sources
- Click Add data source
- Select Prometheus
- Set URL to
http://prometheus:9090 - Click Save & Test
Step 2: Import a Dashboard
Grafana has thousands of pre-built dashboards. Here are some great ones to start with:
For Node Exporter (System Metrics):
- Click + → Import
- Enter dashboard ID:
1860 - Select your Prometheus data source
- Click Import
For Nginx:
- Click + → Import
- Enter dashboard ID:
12708 - Select your Prometheus data source
- Click Import
Understanding the Configuration
Docker Compose Services
Prometheus:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
Grafana:
grafana:
image: grafana/grafana:latest
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
Prometheus Scrape Configuration
The prometheus/prometheus.yml file defines what metrics to collect:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['nodeexporter:9100']
- job_name: 'nginx'
static_configs:
- targets: ['nginxexporter:9113']
Prometheus scrapes metrics every 15 seconds from these endpoints.
Alerting (Bonus)
The setup includes a sample alert configuration in prometheus/alerts.yml:
- alert: HighCPUUsage
expr: node_cpu_seconds_total{mode="idle"} < 20
for: 1m
labels:
severity: warning
annotations:
summary: "CPU usage is high"
You can extend this with more sophisticated alerts based on your needs!
Common Commands
View logs:
docker-compose logs -f prometheus
docker-compose logs -f grafana
Restart a service:
docker-compose restart prometheus
Stop everything:
docker-compose down
Stop and remove volumes (clean slate):
docker-compose down -v
What's Next?
Now that you have a working monitoring stack, you can:
- Add more exporters - MySQL, PostgreSQL, Redis, etc.
- Create custom dashboards - Visualize metrics specific to your apps
- Set up alerting - Get notified via Slack, email, or PagerDuty
- Monitor custom applications - Instrument your code with Prometheus client libraries
- Scale it up - Deploy this to production with proper storage and HA setup
Key Takeaways
- Docker Compose makes it trivial to run complex multi-service stacks
- Prometheus is pull-based - it scrapes metrics from exporters
- Grafana provides beautiful, flexible visualization
- Exporters bridge the gap between services and Prometheus
- This setup is production-ready with minimal tweaks (change default passwords!)
Resources
Have questions or suggestions? Drop them in the comments below! 👇
If you found this helpful, give it a ❤️ and share it with your team!
Top comments (0)