0
0
Dockerdevops~30 mins

Prometheus for Docker monitoring - Mini Project: Build & Apply

Choose your learning style9 modes available
Prometheus for Docker monitoring
📖 Scenario: You want to monitor your Docker containers' resource usage using Prometheus. Prometheus will collect metrics from Docker containers so you can see how much CPU and memory they use.
🎯 Goal: Set up a basic Prometheus configuration to monitor Docker containers by scraping metrics from the Docker daemon's metrics endpoint.
📋 What You'll Learn
Create a Docker Compose file with Prometheus service
Add Prometheus configuration file to scrape Docker metrics
Run Prometheus container with the configuration
Verify Prometheus is scraping Docker metrics
💡 Why This Matters
🌍 Real World
Monitoring Docker containers helps keep applications healthy and performant by tracking resource usage.
💼 Career
DevOps engineers often set up Prometheus to monitor containerized applications in production environments.
Progress0 / 4 steps
1
Create Docker Compose file with Prometheus service
Create a file named docker-compose.yml with a service called prometheus using the image prom/prometheus:latest. Map port 9090 on the host to port 9090 in the container. Mount the local file prometheus.yml to /etc/prometheus/prometheus.yml inside the container as a read-only volume.
Docker
Need a hint?

Use the prom/prometheus:latest image and map port 9090. Mount the config file prometheus.yml as read-only.

2
Create Prometheus configuration file to scrape Docker metrics
Create a file named prometheus.yml with a scrape_configs section. Add a job named docker that scrapes metrics from http://host.docker.internal:9323/metrics every 15 seconds.
Docker
Need a hint?

Use scrape_configs with a job named docker. Set scrape_interval to 15 seconds and target host.docker.internal:9323.

3
Run Prometheus container with Docker Compose
Run the command docker-compose up -d in the terminal to start the Prometheus container with the configuration.
Docker
Need a hint?

Use docker-compose up -d to start Prometheus in detached mode.

4
Verify Prometheus is scraping Docker metrics
Run the command curl http://localhost:9090/metrics in the terminal and check that the output contains the string container_cpu_usage_seconds_total.
Docker
Need a hint?

Use curl http://localhost:9090/metrics and look for container_cpu_usage_seconds_total in the output.