Skip to main content

Prometheus and Loki Configuration and Deployment Using Docker

Prometheus Configuration (prometheus.yml)

Configuration File

Create the Prometheus configuration file prometheus.yml as shown below:
In this configuration:
  • Prometheus scrapes metrics from itself (localhost:9090), Loki (loki:3100), Kubernetes pods, and nodes.
  • Kubernetes service discovery is used for pods and nodes, with relabeling to map labels to the appropriate metrics.

Docker Compose Deployment for Prometheus, Loki, and Grafana

docker-compose.yml

Use the following docker-compose.yml file to deploy Prometheus, Loki, and Grafana as Docker services:

Explanation of the Services:

  • Prometheus:
    • Uses the prom/prometheus:v2.41.0 Docker image.
    • Configures Prometheus to use the custom prometheus.yml configuration file.
    • Enables the remote-write-receiver to accept metrics sent from external sources (e.g., EKS or KIND).
  • Loki:
    • Uses the grafana/loki:2.7.0 Docker image.
    • Exposes Loki on port 3100.
    • Mounts a custom loki-config.yml configuration file.
  • Grafana:
    • Uses the grafana/grafana:latest Docker image.
    • Sets the default admin password for Grafana (GF_SECURITY_ADMIN_PASSWORD=admin).
    • Exposes Grafana on port 3000.
    • Depends on the Prometheus and Loki services to be up and running.
    • Persists Grafana data using a Docker volume (grafana-storage).

Networks and Volumes:

  • The services are all connected to the monitoring network, created with the bridge driver.
  • Grafana’s data is persisted with a Docker volume (grafana-storage).

This setup will deploy Prometheus, Loki, and Grafana using Docker Compose, providing centralized logging and monitoring services with external integration support.