How to Deploy Loki with Docker Compose for Scalable Log Aggregation
This guide walks you through Loki's architecture, advantages, installation via Docker Compose, configuration of Promtail, and step‑by‑step commands to set up a high‑availability, multi‑tenant log aggregation system integrated with Grafana.
Loki's first stable version was released on November 19, 2019 by Grafana Labs. It is a horizontally scalable, highly available, multi‑tenant log aggregation system that emphasizes ease of installation and resource efficiency.
Features
Advantages
Loki uses the same label‑based indexing as Prometheus, allowing log queries and metric queries to share labels, reducing storage cost and query switching overhead.
Lower cost compared with ELK, offering better cost‑effectiveness.
Seamless integration with Grafana for log visualization, filtering, and navigation.
Disadvantages
The technology is relatively new, so community forums are less active.
Functionality is focused on log viewing; it lacks the powerful data processing and cleaning capabilities of ELK, and cannot be combined with other big‑data tools for advanced log processing.
Components
1. Loki – the main server that stores logs and handles queries.
2. Promtail – the agent that collects logs and sends them to Loki.
3. Grafana – UI for visualization.The installation uses Docker.
Installation Steps
1.0 Install docker‑compose
curl -L "https://github.com/docker/compose/releases/download/1.28.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose2.0 Download docker‑compose.yaml
wget https://raw.githubusercontent.com/grafana/loki/v2.2.0/production/docker-compose.yaml -O docker-compose.yaml version: "3"
networks:
loki:
services:
loki:
image: grafana/loki:2.0.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki
promtail:
image: grafana/promtail:2.0.0
volumes:
- /var/log:/var/log
command: -config.file=/etc/promtail/config.yml
networks:
- loki
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
networks:
- loki3.0 Start services docker-compose -f docker-compose.yaml up 4.0 Verify services
Open http://192.168.106.202:3000/ (default Grafana credentials: admin/admin).
5.0 Configure data source in Grafana
Set the Loki endpoint and test the connection.
6.0 Promtail configuration details
Promtail runs as a container that reads logs from /var/log and pushes them to Loki.
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log7.0 Add a second server for log collection
Create a config.yml for the new Promtail instance and a corresponding docker-compose.yaml:
mkdir /root/promtail && cd /root/promtail
cat config.yml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://192.168.106.202:3100/loki/api/v1/push
scrape_configs:
- job_name: mysql
static_configs:
- targets:
- localhost
labels:
job: mysql
__path__: /var/log/*log version: "v1"
services:
promtail:
image: grafana/promtail:2.0.0
container_name: promtail-node
volumes:
- /root/promtail/config.yml:/etc/promtail/config.yml
- /var/log:/var/log
network_mode: 'host'Start with docker-compose up -d.
8.0 Query logs in Loki
Use Grafana's Explore view to run log queries and retrieve matching log entries.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
