Health checks tell you whether a container is running, but ongoing monitoring helps you see what the application is doing. Grafana turns metrics collected by Prometheus into a dashboard that people can inspect. Both tools can run in containers alongside the application, giving you a consistent view across environments. section 9.0
Start with metrics from the application and Docker runtime. Use the Prometheus UI to check scrape targets and develop queries; use Grafana to display those queries. A dashboard can bring information from several application components together, with each visualization driven by a PromQL query. Filtering and aggregation are enough for the dashboard shown here. section 9.3 section 9.4
To explore a containerized dashboard:
- Set HOST_IP to your computer’s IP address, then start the application with docker-compose-with-grafana.yml. The example scales the access-log service to three containers. section 9.4
- Send requests to the application so the dashboard has metrics to show. section 9.4
- Open Grafana on port 3000. Sign in with admin/admin, change the password when prompted, and navigate to the application dashboard. section 9.4
Add an HTTP-error panel
Use the query `sum(image_gallery_requests_total{code="500"}) without(instance)` for a panel showing 500 responses across application instances. It follows the same pattern as the other dashboard visualizations: filter a metric, then aggregate it. Grafana’s toolbar lets you add panels, choose a time period, and save the dashboard. section 9.4
Listing 9.3 The Dockerfile to package a custom Grafana image
FROM diamol/grafana:6.4.3
COPY datasource-prometheus.yaml ${GF_PATHS_PROVISIONING}/datasources/
COPY dashboard-provider.yaml ${GF_PATHS_PROVISIONING}/dashboards/
COPY dashboard.json /var/lib/grafana/dashboards/
For a repeatable setup, this Dockerfile packages the Prometheus data-source configuration, dashboard-provider configuration, and dashboard JSON into a custom Grafana image. section 9.4
For practice, run the metrics-enabled to-do list application with Prometheus and Grafana in Docker Compose. Configure Prometheus to scrape it, then build a dashboard for tasks created, total HTTP requests, and requests currently being processed. The metrics are already in the application image, so the task is to connect and display them rather than change its source code. section 9.6








