Operations 8 min read

Build a Complete Prometheus Monitoring Stack with Docker

This tutorial explains Prometheus' core components, shows how to deploy Prometheus Server, Node Exporter, cAdvisor, and Grafana as Docker containers on two hosts, configures scraping and alerting, and demonstrates visualizing metrics with ready‑made Grafana dashboards.

Raymond Ops
Raymond Ops
Raymond Ops
Build a Complete Prometheus Monitoring Stack with Docker

Prometheus is a powerful monitoring tool that provides a complete solution including data collection, storage, processing, visualization, and alerting.

Key Components

Prometheus consists of four main modules: Prometheus Server, Exporter, Alertmanager, and a visualization component (Grafana).

Prometheus Server pulls metrics from Exporters, stores them, and offers the PromQL query language.

Exporter collects performance data from hosts or containers and exposes it via HTTP.

Alertmanager receives alerts from the server and dispatches notifications according to defined rules.

Visualization was originally built into Prometheus but is now commonly replaced by Grafana for richer dashboards.

Hands‑On Lab

1. Environment Setup

The lab monitors two hosts (192.168.0.101 and 192.168.0.102) and runs the following containers:

Prometheus Server (host 192.168.0.102)

Node Exporter (collects host hardware and OS metrics)

cAdvisor (collects container metrics)

Grafana (visualizes the data)

ip

Node Exporter

cAdvisor

Prometheus Server

Grafana

192.168.0.101

192.168.0.102

2. Run Node Exporter

<code>docker run -d --name node-exporter -p 9100:9100 \
 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" \
 --restart=always --net="host" \
 prom/node-exporter \
 --path.procfs /host/proc --path.sysfs /host/sys \
 --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"</code>

Use

--net="host"

so the exporter can communicate directly with Prometheus. Access

http://<host_ip>:9100/metrics

to verify.

Node Exporter metrics page
Node Exporter metrics page

3. Run cAdvisor

<code>docker run -v /:/rootfs:ro -v /var/run:/var/run:rw \
 -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro \
 -p 8080:8080 -t --name cadvisor --net="host" \
 google/cadvisor:latest</code>

Again

--net="host"

enables direct communication with Prometheus.

cAdvisor UI
cAdvisor UI

4. Run Prometheus Server

<code>docker run -d -p 9090:9090 \
 -v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
 --name prometheus --net host \
 prom/prometheus</code>

The

prometheus.yml

configuration defines a global scrape interval of 15 seconds and a

static_config

that lists the exporter endpoints (e.g.,

192.168.0.101:9100

,

192.168.0.102:9100

, etc.).

Opening

http://192.168.0.102:9090

and navigating to the *Status → Targets* page shows all targets as *UP*, confirming successful data collection.

Prometheus Targets UI
Prometheus Targets UI

5. Install Grafana

<code>docker run -d -p 3000:3000 \
 -e "GF_SERVER_ROOT_URL=http://grafana.server.com" \
 -e "GF_SECURITY_ADMIN_PASSWORD=admin@123" \
 --net="host" grafana/grafana</code>

Access

http://192.168.0.102:3000

, add Prometheus as a data source, and import a ready‑made dashboard JSON to visualize host metrics.

Grafana login screen
Grafana login screen
Grafana dashboard import
Grafana dashboard import
MonitoringDockerprometheusGrafanaAlertmanagerExportercAdvisor
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.