Skip to main content
If Prometheus is already collecting metrics from your Linux hosts, you can extend that visibility into containerized workloads. This guide explains two common ways to gather container-related metrics and how to configure Prometheus to scrape them:
  • Docker Engine metrics (engine-level metrics)
  • Per-container metrics using cAdvisor
Before you begin, ensure:
  • Prometheus is reachable and configured to reload or be restarted after config updates.
  • You have administrative access to the Docker host(s).
  • Networking between Prometheus and the target host/ports is allowed by firewalls/security groups.

Overview

Metrics from containerized environments can come from either the Docker daemon itself (engine metrics) or from an agent that inspects running containers (cAdvisor). Use engine metrics for daemon-level telemetry and cAdvisor for per-container resource usage and lifecycle details.

Docker Engine metrics

Docker exposes an experimental metrics endpoint on the host daemon. To enable it:
  1. Edit or create /etc/docker/daemon.json and add:
  1. Restart Docker and verify the endpoint:
You should receive Prometheus-style metrics at that endpoint. Prometheus scrape job example (engine metrics):
Replace 12.1.13.4 with the IP address of your Docker host (or DNS name) and ensure the port matches metrics-addr in daemon.json.
Exposing Docker’s metrics endpoint can reveal operational details about your host. Binding to 127.0.0.1 restricts access to the local machine; do not bind to a public interface unless you have proper network controls and authentication in place.

cAdvisor (container-level metrics)

cAdvisor (Container Advisor) collects resource usage and performance characteristics for each running container. It runs as a container and needs access to host paths and permissions to gather accurate per-container metrics. Example Docker Compose file (docker-compose.yml) to run cAdvisor:
Start cAdvisor and verify metrics:
Prometheus scrape job example (cAdvisor):
Run cAdvisor on the same Docker host whose containers you want to monitor. It requires privileged access and read-only mounts to several host paths so it can inspect container state and metrics. For full configuration details and explanation of mounts/flags, see the cAdvisor repository on GitHub: https://github.com/google/cadvisor

Prometheus: combined example

Here is an example showing both jobs in a single Prometheus scrape_configs block:
Adjust targets to the actual IP addresses or DNS names of your hosts. If you run Prometheus in Kubernetes, use kubernetes_sd_configs, file_sd_configs, or relabeling to discover hosts dynamically.

What’s the difference between Docker Engine metrics and cAdvisor metrics?

A presentation slide titled "Docker Metrics vs cAdvisor Metrics" comparing two lists: Docker Engine metrics on the left (overall CPU usage, total failed image builds, time to process container actions, no container-specific metrics) and cAdvisor metrics on the right (per-container CPU/memory, number of processes, container uptime, metrics on a per-container basis).

Summary

  • Use Docker Engine metrics for daemon-focused telemetry and operational counts.
  • Use cAdvisor when you need per-container resource metrics and lifecycle information.
  • Configure Prometheus scrape jobs to point at the appropriate host and port; secure endpoints appropriately.
Links and references

Watch Video

Practice Lab