What's the expected behavior from this merged PR "Provide Docker target and discovery in Promtail. #4911"

Hi,

This PR was merged 8 days ago. Provide Docker target and discovery in Promtail. by jeschkies · Pull Request #4911 · grafana/loki · GitHub

I am doing “docker pull grafana/promtail:main” ( see “Docker Hub”) which is a promtail docker image built by garafanabot 10 hours ago. I assume it should include this merge from 8 days ago.

However, I don’t see the log file name contain any human-readable container name; they are still all digits. Am I looking at the wrong place? My promtail-config.yaml is like this:

server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients:

  • url: http://LOKI_HOST_AND_PORT/loki/api/v1/push

scrape_configs:

  • job_name: system
    static_configs:

    • targets:
      • localhost
        labels:
        job: varlogs
        path: /var/log/*log
  • job_name: containers
    static_configs:

    • targets:
      • localhost
        labels:
        job: containerlogs
        path: /var/lib/docker/containers/*/*log

The log files under /var/lib/docker/containers are:

ssgroot@at2-ranch01:~/images$ sudo ls -al /var/lib/docker/containers
total 168
drwx–x— 38 root root 20480 Feb 1 22:28 .
drwx–x— 13 root root 4096 Jan 4 09:17 …
drwx–x— 4 root root 4096 Feb 1 21:42 0040e7c1ff4931c801a82cbfc5478998747be708100f00eaf8978d76fd3b9d57
drwx–x— 4 root root 4096 Jan 4 09:18 0292c51dd8b92ae80c7212ec1781f0d1535aaebe5e6c67181ad184cd5a68eb0c
drwx–x— 4 root root 4096 Feb 1 21:33 0addcd01633b5ca73d8dd9bb8cc94de0025a5df49b40d5e513540f40def4ebe0
drwx–x— 4 root root 4096 Jan 4 09:19 210c33408dc21515507e091a1ad0824e5123158dcc98dfa53e9631bae2278a92
drwx–x— 4 root root 4096 Feb 1 21:47 23e50d5452bbe8c21d18622b4ad2de02a7881149b761f1dff03e85f613957140
drwx–x— 4 root root 4096 Jan 4 09:19 2d139d103eec7042b5076aa27d66795db2389f74bbeab2190de2886c307d1402
drwx–x— 4 root root 4096 Feb 1 21:41 3518677eefa57b6d8612d35458b240ed81b26d70e98ccfa43660217c8a9784ea
drwx–x— 4 root root 4096 Jan 4 09:19 357d7cdd7f988c5f4cd3850c5bd16eae591f48e89cbf4b2632cde66ce028f157
drwx–x— 4 root root 4096 Jan 4 09:18 3995432e9f5a8625ffe296971e13246930c6e62b64f6ef4110871dca733ad486
drwx–x— 4 root root 4096 Jan 4 09:19 3b1aaee8d1eb660bc4c656b7d91932d472edd2bd420f4dabb3374b52c0e8b737
drwx–x— 4 root root 4096 Jan 4 09:19 3fc386a4a0a88f8a72aaff2f20548be02d829df02a4fb2cc7280a18d330e648e
drwx–x— 4 root root 4096 Feb 1 21:38 4a0a113a6b2cd8e3bdab7c4fb04cc47cd076b4cadb9619e08c955d1cd20736eb
drwx–x— 4 root root 4096 Jan 4 09:19 5086575f6091ce3c3904ad8f975cf6c5c3e92368d8aaf2cd055bf1841eb627eb
drwx–x— 4 root root 4096 Feb 1 21:45 51754ca9c38d661404c207c03a56231c4f1e74ae1b7fe17e5ff27771f4e3f6a2
drwx–x— 4 root root 4096 Jan 4 09:18 54102b1eaa623c20c22594f591da034fa24866551b71010efe889d15b8226de9
drwx–x— 4 root root 4096 Jan 4 09:18 688b365ae94072f4d2db267b8d1dff7c561759922ce1fb3a9ede098057e4ec89

Is this “/var/lib/docker/containers” the right place to find the containers’ log files? What’s the expected behavior from this PR/merge? Please advise.

Thanks!
-Lu

Hi,
I figure it out myself. To use this feature, change the promtail-config.yaml like this:

server:
http_listen_port: 9080
grpc_listen_port: 0
log_level: “debug”

positions:
filename: /tmp/positions.yaml

clients:

  • url: http://LOKI_HOST_AND_PORT/loki/api/v1/push

scrape_configs:

  • job_name: system
    static_configs:

    • targets:
      • localhost
        labels:
        job: varlogs
        path: /var/log/*log
  • job_name: docker
    docker_sd_configs:

    • host: unix:///var/run/docker.sock
      refresh_interval: 5s
      relabel_configs:
    • source_labels: [’__meta_docker_container_name’]
      regex: ‘/(.*)’
      target_label: ‘container’

Then I am able to see a “container” label in Grafana which is populated by this docker service discovery feature. Or use loki query {container="<YOUR_CONTAINER_NAME>"}.

Thanks,
Lu