
Loki is an open-source log aggregation system designed for efficiently storing and querying logs from your applications and infrastructure. Unlike traditional log management systems, Loki indexes only label key-value pairs rather than the full-text log content, making it cost-effective and highly scalable for cloud-native environments.
In this article, you will deploy Loki using Docker Compose, configure persistent storage for log data, and set up Traefik as a reverse proxy to securely access your Loki instance.
Before you begin, you need to:
sudo privileges.loki.example.com).In this section, you prepare the required directory structure for Loki and define environment variables in a .env file.
Create the directory structure for Loki.
These directories store Loki's log chunks, indexes, and configuration files.
Navigate into the loki-logging directory.
Set proper ownership for the Loki data directory. Loki runs as the loki user (UID 10001) inside the container.
Create a .env file.
Add the following variables:
Replace:
loki.example.com with your domain.admin@example.com with your email.Save and close the file.
Create a Loki configuration file.
Add the following content.
Save and close the file.
This configuration enables local filesystem storage and sets up the indexing schema. The tsdb index store provides efficient time-series based querying of log metadata, while the filesystem object store saves the actual log chunks and metadata in the mounted data directory.
In this section, you create and deploy the Docker Compose stack that runs Loki behind Traefik. Docker Compose manages both containers, applies the environment variables from your .env file, and automatically configures HTTPS routing through Traefik.
Create a new Docker Compose manifest.
Add the following content.
Save and close the file.
The manifest structure consists of:
letsencrypt volume maintains certificate persistence through container updates.Create and start the services.
Verify that the services are running.
Output:
Both containers are running successfully. Loki is ready to accept log streams while Traefik accepts connections on ports 80 and 443.
View the logs of the services.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
In this section, you access the Loki API to verify your installation by checking service readiness and querying available labels.
Check the service readiness endpoint.
Output:
This confirms Loki is operational and accepting requests.
Query available label names in Loki.
Output:
An empty array is expected on a fresh installation with no log data. When logs are ingested, the endpoint returns label names like job, instance, and any custom labels you have configured.
Verify the Loki version and build information.
Output:
Output displays the version, Go version, and build timestamp. This confirms Loki is responding correctly to API requests.
You have successfully deployed Loki for log aggregation with HTTPS encryption. Container orchestration through Docker Compose ensures reliable operation, while volume mounts preserve log chunks and indexes permanently. Automated TLS certificate provisioning from Let's Encrypt maintains secure communications as Traefik efficiently routes requests. The system now awaits log ingestion from distributed applications and infrastructure services via its RESTful API interface.
0 Comments
Be the first to comment and share your perspective with the community.