How to install Prometheus & Grafana with Docker

Prometheus and Grafana are two powerful open-source tools that work together to create a complete monitoring stack for your server. Prometheus collects and stores metrics, while Grafana visualizes that data in beautiful, customizable dashboards. This guide shows you how to set them up using Docker Compose.

Prometheus LogoGrafana Logo
Prerequisites:
  • A server running a modern Linux distribution (e.g., Ubuntu 22.04).
  • Docker and Docker Compose installed. You can find the official guide here: Install Docker Engine on Ubuntu.
  • A domain name pointing to your server's IP address (recommended for accessing Grafana).

Installation Steps

First, create a directory for your monitoring stack. Inside it, create a subdirectory for the Prometheus configuration.

Create Directories
mkdir monitoring-stack cd monitoring-stack mkdir prometheus_config

Now, create the Prometheus configuration file named prometheus.yml inside the new subdirectory:

Create Prometheus Config File
nano prometheus_config/prometheus.yml

Paste the following basic configuration. This tells Prometheus to monitor itself and an agent called "node-exporter", which we will set up next.

prometheus.yml
global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node-exporter' static_configs: - targets: ['node-exporter:9100']