promtail-config.yml, how labels work, and how to extend the configuration to collect additional log paths.
Full configuration
Configuration fields
The port Promtail’s HTTP server listens on inside the container. Because
docker-compose.yml does not expose this port to the host, http://localhost:9080 is not accessible from your browser. The endpoint is reachable from other containers on the same Docker network, for example for health checks from within the stack.Path to the file where Promtail persists its read offsets for each tailed log file.
The Loki endpoint Promtail pushes log batches to. The URL
http://loki:3100/loki/api/v1/push uses the Docker internal DNS name loki, which resolves to the Loki container because both services share the same Docker Compose network.A unique name for this scrape job. The value
system is used here to describe logs from the host operating system.The scrape target. For file-based log collection this is always
localhost, because Promtail reads files on the same filesystem it runs on (via the Docker volume mount).A label attached to every log line collected by this job. The value
varlogs identifies these logs in Loki. You query them in Grafana with {job="varlogs"}.A glob pattern that tells Promtail which files to tail. The pattern
/var/log/*.log matches all .log files directly inside /var/log. Promtail automatically discovers new files that match the pattern without a restart.How labels work in Loki
Every log line Promtail pushes to Loki carries the labels defined inscrape_configs. Labels are the primary way to filter and query logs in Loki’s query language (LogQL).
With the configuration above, all logs from /var/log/*.log are tagged with job="varlogs". In Grafana’s Explore view you can retrieve them with:
error:
Docker Compose volume mount
Thepromtail service in docker-compose.yml mounts the host log directory into the container:
/var/log:/var/log:ro gives Promtail read-only access to the host’s /var/log directory. The :ro flag prevents Promtail from modifying any log files.
Adding more log paths
To collect logs from an additional directory, add a new entry underscrape_configs with a different job label and __path__ value:
/var/log, you also need to add a matching volume mount in docker-compose.yml so the directory is accessible inside the Promtail container.