Bird
Raised Fist0
Dockerdevops~30 mins

Grafana dashboards for containers in Docker - Mini Project: Build & Apply

Choose your learning style10 modes available
Grafana Dashboards for Containers
📖 Scenario: You work in a small team managing containerized applications. You want to monitor your containers' performance using Grafana dashboards. This project will guide you to set up a simple Docker Compose file that runs Prometheus and Grafana containers, and configure Grafana to display container metrics.
🎯 Goal: Build a Docker Compose setup that runs Prometheus and Grafana containers. Configure Grafana to connect to Prometheus as a data source and prepare a basic dashboard to monitor container metrics.
📋 What You'll Learn
Create a Docker Compose file with Prometheus and Grafana services
Add a Prometheus configuration file to scrape container metrics
Configure Grafana to use Prometheus as a data source
Verify Grafana dashboard is accessible and shows container metrics
💡 Why This Matters
🌍 Real World
Monitoring container performance is essential in real-world DevOps to ensure applications run smoothly and issues are detected early.
💼 Career
This project teaches skills used by DevOps engineers and site reliability engineers to set up monitoring and observability for containerized environments.
Progress0 / 4 steps
1
Create Docker Compose file with Prometheus and Grafana
Create a file named docker-compose.yml with two services: prometheus and grafana. Use the images prom/prometheus:latest and grafana/grafana:latest. Map port 9090 for Prometheus and port 3000 for Grafana. Mount a local directory ./prometheus to /etc/prometheus/ in the Prometheus container.
Docker
Hint

Use version: '3.8' at the top. Define two services with correct images, ports, and volume for Prometheus.

2
Add Prometheus scrape configuration
Create a file named prometheus/prometheus.yml with a scrape config to monitor Docker containers. Use job_name: 'docker' and scrape targets at 'host.docker.internal:9323'. Set scrape interval to 15s.
Docker
Hint

Define scrape_configs with job_name, scrape_interval, and static_configs with the target address.

3
Configure Grafana to use Prometheus data source
Add environment variables to the grafana service in docker-compose.yml to set up Prometheus as a data source automatically. Use GF_SECURITY_ADMIN_PASSWORD=admin and GF_DATASOURCES_PROMETHEUS_URL=http://prometheus:9090.
Docker
Hint

Add an environment section under grafana with the two variables exactly as shown.

4
Start containers and verify Grafana dashboard
Run docker-compose up -d in your terminal to start Prometheus and Grafana containers. Then, open http://localhost:3000 in your browser. Log in with username admin and password admin. Verify you can add Prometheus as a data source and see container metrics.
Docker
Hint

Use the terminal command docker-compose up -d to start containers. Open Grafana in your browser and log in with admin for both username and password.

Practice

(1/5)
1. What is the primary purpose of using Grafana dashboards for Docker containers?
easy
A. To write Dockerfiles automatically
B. To visually monitor container health and performance metrics
C. To build Docker images faster
D. To deploy containers without configuration

Solution

  1. Step 1: Understand Grafana's role

    Grafana is a tool designed to visualize data, especially metrics and logs.
  2. Step 2: Connect Grafana to container metrics

    When connected to data sources like Prometheus, Grafana shows container health and performance visually.
  3. Final Answer:

    To visually monitor container health and performance metrics -> Option B
  4. Quick Check:

    Grafana = Visual monitoring [OK]
Hint: Grafana = Visual dashboards for metrics [OK]
Common Mistakes:
  • Confusing Grafana with image building tools
  • Thinking Grafana deploys containers
  • Assuming Grafana writes Dockerfiles
2. Which Docker command correctly runs Grafana exposing it on port 3000?
easy
A. docker run -d -p 80:3000 grafana/grafana
B. docker run -d -p 8080:3000 grafana/grafana
C. docker run -d -p 3000:8080 grafana/grafana
D. docker run -d -p 3000:3000 grafana/grafana

Solution

  1. Step 1: Identify Grafana default port

    Grafana listens on port 3000 inside the container.
  2. Step 2: Map host port 3000 to container port 3000

    The correct syntax is -p hostPort:containerPort, so -p 3000:3000 exposes Grafana on host port 3000.
  3. Final Answer:

    docker run -d -p 3000:3000 grafana/grafana -> Option D
  4. Quick Check:

    Port mapping = host:container [OK]
Hint: Map host port 3000 to container port 3000 [OK]
Common Mistakes:
  • Swapping host and container ports
  • Using wrong ports like 8080 or 80
  • Not running container in detached mode
3. Given this Docker command, what will happen when you access http://localhost:3000?
docker run -d -p 3000:3000 grafana/grafana
medium
A. You will see the Docker container logs
B. You will get a 404 Not Found error
C. You will see the Grafana login page
D. The browser will fail to connect

Solution

  1. Step 1: Understand port mapping

    Port 3000 on localhost is forwarded to Grafana's port 3000 inside the container.
  2. Step 2: Accessing localhost:3000 loads Grafana UI

    Grafana serves its web interface on port 3000, so the login page appears.
  3. Final Answer:

    You will see the Grafana login page -> Option C
  4. Quick Check:

    Port 3000 mapped = Grafana UI loads [OK]
Hint: Port 3000 access shows Grafana login [OK]
Common Mistakes:
  • Expecting error pages instead of UI
  • Confusing logs with web interface
  • Assuming no connection due to missing config
4. You ran Grafana with docker run -d -p 3000:3000 grafana/grafana but cannot access the dashboard at http://localhost:3000. What is a likely cause?
medium
A. Grafana container is not running or crashed
B. You used the wrong image name
C. Port 3000 is not exposed inside the container
D. Docker daemon is not installed

Solution

  1. Step 1: Check container status

    If the container stopped or crashed, the port won't be accessible.
  2. Step 2: Verify container is running

    Use docker ps to confirm Grafana container is active.
  3. Final Answer:

    Grafana container is not running or crashed -> Option A
  4. Quick Check:

    Container running = Dashboard accessible [OK]
Hint: Check container status with docker ps [OK]
Common Mistakes:
  • Assuming wrong image name without checking
  • Thinking port exposure inside container is missing
  • Ignoring Docker daemon status
5. You want to monitor multiple Docker containers' CPU and memory usage in Grafana. Which setup step is essential before creating dashboards?
hard
A. Connect Grafana to a metrics data source like Prometheus collecting container stats
B. Install Grafana plugins inside each container
C. Run Grafana with extra CPU and memory limits
D. Expose all container ports to the host

Solution

  1. Step 1: Understand Grafana data source role

    Grafana itself does not collect metrics; it visualizes data from sources like Prometheus.
  2. Step 2: Set up Prometheus to scrape container metrics

    Prometheus collects CPU and memory stats from Docker containers and provides data to Grafana.
  3. Step 3: Connect Grafana to Prometheus

    Configure Grafana to use Prometheus as a data source to build dashboards.
  4. Final Answer:

    Connect Grafana to a metrics data source like Prometheus collecting container stats -> Option A
  5. Quick Check:

    Data source connection = Dashboard data [OK]
Hint: Grafana needs data source like Prometheus first [OK]
Common Mistakes:
  • Thinking Grafana collects metrics alone
  • Installing plugins inside containers unnecessarily
  • Exposing all ports without reason
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard