Add container name to promtail docker logs

I run successfully a centralized loki logging for several docker servers with multiple images running on them. When I now look via grafana into the logs and needs to filter for one virtual container output I have no hint for the docker container name.

current promtail config is partly this one:

# which logs to read/scrape
  - job_name: docker-logs
    - docker: {}
    - targets: # tells promtail to look for the logs on the current machine/host
        - localhost
      labels: # labels with which all the following logs should be labelled
        job: container
        host: docker    # label-1
        __path__: /var/lib/docker/containers/*/*-json.log
        # __path__ denotes the path of the actual log file whose logs will be scraped
        # and shipped to loki indexed with the above labels

Now in the log view I only see the hostname where all docker images are running under.

In addition I would like to extract the NAMES property of that docker, like diun here.

Hi @kai ,

I got curious and Googled this. This is not something I have tested myself but I have struggled with Promtail configurations in the past

Looking at this, there seems to be a good example that is called job_name: containers in the first version of docker-config.yml.

Hope that helps.

Without using service discovery, I think you have to take care of all the labeling config yourself. Don’t think there is any mechanism for automatic Docker metadata discovery…

1 Like

That seems to be a way, sadly the syntax has changed since that post.
So I will have to play around with that instead of just C&P to a solution. I’ll reply again if I get any further. Thanks so far.

I just found out that simply using the loki logging plugin for docker already adds the tags for container and composer I needed. So now it is with all the filter info I needed.