Prometheus LogoGrafana Logo

Install Prometheus & Grafana with Docker

Prometheus and Grafana together form a complete monitoring stack for your server. Prometheus collects and stores metrics, while Grafana visualizes that data in customizable dashboards.

Prerequisites:
✓ A server running a recent Linux distribution (e.g. Ubuntu 22.04)
Docker and Docker Compose installed on the server
✓ A domain name pointing to your server's IP address (recommended for accessing Grafana)

Step 1: Create the Directory Structure and Configuration

Create a directory for your monitoring stack and a subdirectory for the Prometheus configuration:

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

Now create the Prometheus configuration file:

Open Prometheus Config File
nano prometheus_config/prometheus.yml

Paste the following base configuration. It instructs Prometheus to monitor itself and the Node Exporter, which we will set up in the next step:

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']

Step 2: Create the Docker Compose File

In the root of your monitoring-stack directory, create the Compose file:

Open Docker Compose File
nano docker-compose.yml

Paste the following content. The file defines three services: Prometheus for metric collection, Grafana for visualization, and Node Exporter which exposes your server's metrics:

docker-compose.yml
version: '3.8' services: prometheus: image: prom/prometheus:latest container_name: prometheus restart: unless-stopped volumes: - ./prometheus_config:/etc/prometheus - ./prometheus_data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' ports: - '9090:9090' grafana: image: grafana/grafana-oss:latest container_name: grafana restart: unless-stopped volumes: - ./grafana_data:/var/lib/grafana ports: - '3000:3000' node-exporter: image: prom/node-exporter:latest container_name: node-exporter restart: unless-stopped volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - '--path.rootfs=/rootfs' - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'

Step 3: Start the Monitoring Stack

Start all three containers with a single command:

Start Docker Compose
docker compose up -d

Docker will pull the images and start Prometheus, Grafana, and Node Exporter in the background.

Step 4: Connect Grafana to Prometheus

Open your browser and navigate to http://YOUR_SERVER_IP:3000. Log in with the default credentials — username admin, password admin. You will be prompted to set a new password immediately.

1.Navigate to Connections → Data Sources in the left menu
2.Click Add data source and select Prometheus
3.Enter http://prometheus:9090 as the Prometheus server URL
4.Click Save & test — a green checkmark confirms the connection is working

Step 5: Import a Dashboard

Import a pre-built dashboard to start visualizing your server metrics right away:

1.Navigate to Dashboards → New → Import in the left menu
2.Enter dashboard ID 1860 — a widely used dashboard for server monitoring
3.Click Load and select your Prometheus data source on the next screen
4.Click Import — you will now see a full dashboard with CPU, RAM, disk, and network usage for your server

Further Documentation

For advanced configurations, custom dashboards, and alerting setup, refer to the official documentation for each tool.