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.
Ubuntu Docker - Metrics with Grafana, cAdvisor, and Node Exporter
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:
sudo mkdir /etc/prometheus
sudo nano /etc/prometheus/prometheus.ymlAdd the following configuration with a 15-second scrape interval:
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:
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.1After 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:
- Launch Grafana and log in with default credentials (username and password both "admin")
- Click the hamburger menu and select "Connections"
- Search for and select "Prometheus"
- Click "Add new data source"
- Enter your Prometheus server URL (including port 9090)
- 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.