Grafana Loki is a horizontally scalable log aggregation system inspired by Prometheus: it indexes only labels per log stream instead of full text, so it uses less storage and is easier to run—especially if you already use Prometheus or Kubernetes. Promtail ships log files to Loki; Grafana is the UI where you add Loki as a data source and query logs with LogQL. This guide walks you through running Grafana Loki, Promtail, and Grafana with Docker and Docker Compose for local or dev use, then querying logs in Grafana Explore.
In this guide you’ll:
- Verify Docker and Docker Compose, then run Grafana in a container
- Run Loki and Promtail with Docker using
loki-config.yamlandpromtail-config.yaml - Run the full stack with a single
docker compose up -d - Add Loki as a Grafana data source and query system logs with LogQL in Explore
For production, use Loki in distributed mode with Helm or Tanka and persistent storage (e.g. S3, GCS).
Related guides:
- How to run Grafana OSS in Docker and Docker Compose
- How to run Prometheus with Docker and Docker Compose
- How to set up Promtail, Grafana and Loki for log management in Debian 11
- How to run Grafana Loki with Helm and Kustomize in Kubernetes
- How to install and configure Prometheus on a Linux server
Prerequisites: Docker and Docker Compose
You need Docker and Docker Compose installed. On Ubuntu, see How to install and use Docker in Ubuntu 22.04.
Confirm that Docker is working as expected:
| |
Docker Compose is now included with Docker Desktop and is available on Linux as a Docker plugin. Confirm it’s available with:
| |
Run Grafana in Docker
Grafana is an open source analytics and visualization platform. For this setup, Grafana is the UI for Loki: you’ll use it to add Loki as a data source, run LogQL queries in Explore, and build dashboards from your logs.
Run Grafana OSS in a container with:
| |
The -d flag runs the container in the background. When it’s up, open Grafana at http://localhost:3000 (or http://your_server_ip:3000).
Run Loki with Docker
Loki is the log backend; Promtail is the agent that tails local log files and sends them to Loki. Together they give you log aggregation and search that fits well with Prometheus and Kubernetes.
First, create a working directory:
| |
Next, create a configuration file required to start and run Loki. Save this as loki-config.yaml:
| |
Now we can run our loki instance with this command:
| |
Once Loki is running, run Promtail to ship logs from /var/log/*log to Loki. Create a file named promtail-config.yaml:
| |
Start promtail with this command:
| |
When Loki and Promtail are running, check Loki’s metrics at http://localhost:3100/metrics and readiness at http://localhost:3100/ready.
Tip: Some Loki and Promtail images run as a non-root user. If bind mounts cause permission errors, fix directory permissions or run the container with --user 0 (root).
Run the full stack with Docker Compose
A Docker Compose file lets you start and manage Grafana, Loki, and Promtail with one command. Put the following in docker-compose.yaml in the same directory as your config files.
Add the following to a docker-compose.yaml file:
| |
From the directory that contains docker-compose.yaml and the config files, start everything with:
| |
Grafana stays at port 3000, Loki at 3100. Use the same URLs as in the previous sections.
Add Loki as a data source and query logs
- Log in to Grafana at
http://localhost:3000with the default useradminand passwordadmin. Change the password when prompted. - Add Loki: Open the menu (Grafana icon) → Connections → Data sources → Add data source → Loki. Set URL to
http://loki:3100and click Save & test. - Query logs: Go to Explore, select Loki, then use the label browser to pick
job→varlogs(for/var/log/*log). Run a query such as:
| |
To hide lines that fail logfmt parsing, add:
| |
You should see logs from your system streaming in.
Frequently Asked Questions (FAQ)
What is Grafana Loki?
Grafana Loki is a log aggregation system that indexes only label metadata for log streams (similar to how Prometheus indexes metrics), not full log content. That reduces storage and operational cost. You query logs with LogQL in Grafana after adding Loki as a data source.
What is Promtail?
Promtail is the log shipper for Loki. It discovers log files (e.g. under /var/log), adds labels, and pushes log lines to Loki. It plays a similar role to Fluentd or Filebeat for the Loki stack.
How do I run Loki with Docker Compose?
Create a docker-compose.yaml with services for grafana, loki, and promtail on a shared network. Mount loki-config.yaml and promtail-config.yaml, use named volumes for Loki and Promtail data, then run docker compose up -d. Loki listens on port 3100, Grafana on 3000.
Can I use this Loki Docker setup in production?
This guide uses single-binary Loki with filesystem storage and in-memory ring, which is suitable for local or dev. For production, run Loki in distributed mode with persistent object storage (S3, GCS) and deploy via Helm or Tanka.
What is LogQL?
LogQL is Loki’s query language (inspired by PromQL). In Grafana Explore with Loki selected, you use it to filter by labels (e.g. {job="varlogs"}) and optionally parse or filter log lines (e.g. | logfmt).
Conclusion
You ran Grafana, Loki, and Promtail with Docker and Docker Compose, added Loki as a Grafana data source, and queried system logs in Grafana Explore using LogQL. For next steps, add dashboards and alerts, or pair this stack with Prometheus in Docker for metrics and logs together.