LocalHake

Tutorial

Monitoring Your Docker Resources and Containers Part 1

The first part of a three-part series on monitoring Docker resources. Covers installing and configuring Prometheus via Portainer stack and connecting it as a data source in Grafana.

Hake HardwarePublished Updated ~5 minintermediate

This post contains paid links (affiliate) — how that works.


▶ Watch this build on YouTube
Contents

Prometheus, Node Exporter, cAdvisor, and Grafana

One of the essential first steps after setting up Docker and Portainer involves establishing resource monitoring. This guide walks through installation and configuration of four key tools: Prometheus (metrics data source), Grafana (visualization and dashboards), Node Exporter (system metrics), and cAdvisor (container-level metrics).

Prometheus Setup

Creating the Configuration File

Begin by establishing the Prometheus configuration directory and file:

bash
sudo mkdir /etc/prometheus
bash
sudo nano /etc/prometheus/prometheus.yml

Add the following configuration with a 15-second scrape interval:

/etc/prometheus/prometheus.ymlyaml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['172.18.0.100:9090']

Deploying via Portainer Stack

In Portainer, navigate to Stacks and create a new stack with this Docker Compose configuration:

docker-compose.ymlyaml
version: '3'
services:
  prometheus: 
    image: prom/prometheus:latest
    container_name: prometheus
    command: "--config.file=/etc/prometheus/prometheus.yml"
    user: root
    volumes:
      - /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    ports:
      - 9090:9090
    networks:
      spacenet:
        ipv4_address: 172.18.0.100

volumes:
  prometheus_data:
  
networks:
  spacenet:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16
          gateway: 172.18.0.1

After deployment, verify the container reaches "running" status. Access Prometheus at https://localhost:9090 (or substitute the host IP when accessing remotely). Navigate to Status > Targets to confirm the Prometheus job shows an "UP" state.

Grafana Integration

Install Grafana using official documentation, then configure it as a data source for Prometheus:

  1. Launch Grafana and log in with default credentials (username and password both "admin")
  2. Click the hamburger menu and select "Connections"
  3. Search for and select "Prometheus"
  4. Click "Add new data source"
  5. Enter your Prometheus server URL (including port 9090)
  6. Select "Save and Test"

This establishes the foundation for creating monitoring dashboards once additional metric collectors (Node Exporter and cAdvisor) are configured in Part 2.

Gear used