Menu

Caution

Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

loki.source.docker

loki.source.docker reads log entries from Docker containers and forwards them to other loki.* components. Each component can read from a single Docker daemon.

Multiple loki.source.docker components can be specified by giving them different labels.

Usage

river
loki.source.docker "LABEL" {
  host       = HOST
  targets    = TARGET_LIST
  forward_to = RECEIVER_LIST
}

Arguments

The component starts a new reader for each of the given targets and fans out log entries to the list of receivers passed in forward_to.

loki.source.file supports the following arguments:

NameTypeDescriptionDefaultRequired
hoststringAddress of the Docker daemon.yes
targetslist(map(string))List of containers to read logs from.yes
forward_tolist(LogsReceiver)List of receivers to send log entries to.yes
labelsmap(string)The default set of labels to apply on entries."{}"no
relabel_rulesRelabelRulesRelabeling rules to apply on log entries."{}"no

Blocks

The loki.source.docker component doesn’t support any inner blocks and is configured fully through arguments.

Exported fields

loki.source.docker does not export any fields.

Component health

loki.source.docker is only reported as unhealthy if given an invalid configuration.

Debug information

loki.source.docker exposes some debug information per target:

  • Whether the target is ready to tail entries.
  • The labels associated with the target.
  • The most recent time a log line was read.

Debug metrics

  • loki_source_docker_target_entries_total (gauge): Total number of successful entries sent to the Docker target.
  • loki_source_docker_target_parsing_errors_total (gauge): Total number of parsing errors while receiving Docker messages.

Example

This example collects log entries from the files specified in the targets argument and forwards them to a loki.write component to be written to Loki.

river
discovery.docker "linux" {
  host = "unix:///var/run/docker.sock"
}

loki.source.docker "default" {
  host       = "unix:///var/run/docker.sock"
  targets    = discovery.docker.linux.targets 
  forward_to = [loki.write.local.receiver]
}

loki.write "local" {
  endpoint {
    url = "loki:3100/api/v1/push"
  }
}