Run Grafana Loki with Docker Compose
Grafana Loki is a cost-effective, highly available log aggregation system inspired by Prometheus. Designed for scalability and ease of use, Loki differs from other logging solutions by indexing only metadata labels instead of full log content. This approach ensures high performance and lower storage costs while providing seamless integration with Grafana and Prometheus for a unified observability workflow.
Key Components of Loki
Efficient Log Collection with Promtail Promtail serves as the primary log collection agent, designed specifically for Loki. It mirrors Prometheus’s service discovery mechanisms, allowing for consistent labeling, filtering, and transformation of log data before it reaches the backend.
Optimized Storage with Label Indexing Unlike traditional logging platforms, Loki focuses on indexing labels rather than the full text of log entries. By grouping logs into streams based on metadata, Loki reduces storage requirements and ensures that logs are searchable almost immediately upon ingestion.
Advanced Analysis with LogQL LogQL provides a robust query language for deep-diving into your logs. Users can execute queries directly within Grafana to correlate logs with metrics or use LogCLI for a streamlined command-line interface experience.
Integrated Alerting Loki supports native alerting rules that evaluate incoming log streams. When specific conditions are met, alerts are dispatched to the Prometheus Alertmanager, facilitating seamless routing and incident response across your infrastructure.
Docker Compose Configuration
The following configuration defines the setup required to deploy Loki using Docker Compose:
services:
loki:
image: grafana/loki:3.6.3
container_name: loki
ports:
- "3100:3100"
command: -config.file=/etc/loki/loki-config.yaml
user: "0"
volumes:
- ./config:/etc/loki
- ./data:/loki
restart: unless-stopped
Next, create the config/loki-config.yaml file to define the Loki settings. You can use the official sample configuration as a starting point.
Launching the Service
To launch the service, execute the following command:
docker compose up -d
Make sure it is running by checking the logs:
docker compose logs -f