logging {
  level = "info"
}

// Promtail-compatible Docker log scraping via the local container engine.
// Requires mounting /var/run/docker.sock and /var/lib/docker/containers.
discovery.docker "containers" {
  host = "unix:///var/run/docker.sock"
}

discovery.relabel "container_labels" {
  targets = discovery.docker.containers.targets

  rule {
    source_labels = ["__meta_docker_container_name"]
    target_label  = "container"
  }

  rule {
    source_labels = ["__meta_docker_container_log_stream"]
    target_label  = "stream"
  }
}

loki.source.docker "default" {
  host       = "unix:///var/run/docker.sock"
  targets    = discovery.relabel.container_labels.output
  forward_to = [loki.write.local.receiver]
  labels = {
    job = "docker",
  }
}

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