1. Blog
  2. Manuals

Install Grafana and Prometheus with Docker: Server Monitoring

Install Grafana and Prometheus with Docker: Server Monitoring

Prometheus and Grafana are the standard pairing for server monitoring. Prometheus collects and stores metrics, Node Exporter exposes operating system figures, and Grafana turns them into readable graphs. With Docker Compose the whole stack is up in a few minutes.

How the stack fits together

  • Node Exporter runs on every server and exposes metrics: CPU load, memory, disks, network.
  • Prometheus polls the exporters every few seconds and stores the values in its database.
  • Grafana queries Prometheus and draws dashboards.

What you need

Step 1. Project files

mkdir -p ~/monitoring && cd ~/monitoring

Create the Prometheus configuration in prometheus.yml:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: node
    static_configs:
      - targets: ["node-exporter:9100"]

Create docker-compose.yml:

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.retention.time=30d
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"

  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    restart: unless-stopped
    command:
      - --path.rootfs=/host
    pid: host
    volumes:
      - /:/host:ro,rslave

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    environment:
      GF_SECURITY_ADMIN_PASSWORD: "a-strong-password"
    volumes:
      - grafana_data:/var/lib/grafana
    ports:
      - "3000:3000"

volumes:
  prometheus_data:
  grafana_data:

Prometheus is published on the loopback address only: it has no built-in authentication and must not be exposed to the internet. The retention.time flag sets how long metrics are kept.

Step 2. Start the stack

docker compose up -d
docker compose ps

All three containers should be in the running state.

Step 3. Check Prometheus

The Prometheus UI is reachable only from the server itself. To open it in your browser, forward the port over SSH:

ssh -L 9090:127.0.0.1:9090 root@203.0.113.10

Open http://localhost:9090 and go to Status → Target health. Both targets — prometheus and node — should be UP.

Step 4. Configure Grafana

Open http://your-server-ip:3000 and log in as admin with the password from docker-compose.yml.

Data source

  1. Go to Connections → Data sources → Add data source.
  2. Choose Prometheus.
  3. Set Prometheus server URL to http://prometheus:9090 — containers reach each other by name.
  4. Click Save & test.

Ready-made dashboard

There is no need to build panels from scratch: the Grafana catalogue has ready-made dashboards.

  1. Go to Dashboards → New → Import.
  2. Enter the ID 1860 (Node Exporter Full) and click Load.
  3. Select the Prometheus data source you created and click Import.

You get a dashboard with CPU, memory, disk and network graphs.

Step 5. Add more servers

On every server you want to monitor, start Node Exporter:

docker run -d \
  --name node-exporter \
  --restart unless-stopped \
  --net host --pid host \
  -v /:/host:ro,rslave \
  prom/node-exporter:latest --path.rootfs=/host

The exporter has no authentication, so allow port 9100 only from the monitoring server’s address:

sudo ufw allow from 203.0.113.10 to any port 9100 proto tcp

Add the servers to prometheus.yml on the monitoring server:

  - job_name: node
    static_configs:
      - targets: ["node-exporter:9100"]
        labels:
          instance: monitoring
      - targets: ["198.51.100.20:9100"]
        labels:
          instance: web-01

Apply the change:

docker compose restart prometheus

The new server appears in the drop-down at the top of the dashboard.

Securing Grafana

  • Close port 3000 and publish Grafana through a reverse proxy with HTTPS — see the Nginx virtual host examples.
  • Self-registration and anonymous access are off by default; leave them off unless you need them.

Updating

cd ~/monitoring
docker compose pull
docker compose up -d

Prometheus data and Grafana settings live in volumes and survive the update.

Next steps

  • Set up notifications under Alerting: Grafana can send alerts to Telegram, email and other channels.
  • Add exporters for your own services: MySQL, PostgreSQL, Nginx, Docker.
  • For classic agent-based monitoring with templates, see Zabbix; for simple uptime checks, Uptime Kuma.