1

UPDATE:

I've tried implementing the accepted answer from here Telegraf can not connect to Docker sock like this in my docker compose file:

telegraf3:
  image: telegraf
  user: telegraf:$$(stat -c '%g' /var/run/docker.sock)    
  volumes:
    - ./telegraf/telegraf3.conf:/etc/telegraf/telegraf.conf
    - /var/run/docker.sock:/var/run/docker.sock

I am getting this error:

Error response from daemon: unable to find group $(stat -c '%g' /var/run/docker.sock): no matching entries in group file

How can i fix this issue? :)

Background:

I'm trying to run Telegraf (https://github.com/influxdata/telegraf) with the docker input. I'm running Telegraf via Docker Compose, and i've configured it roughly like this:

telegraf3:
  image: telegraf
  volumes:
    - ./telegraf/telegraf3.conf:/etc/telegraf/telegraf.conf
    - /var/run/docker.sock:/var/run/docker.sock:rw
  env_file:
    - ./telegraf/telegraf.env
  depends_on:
    - influxdb

The telegraf configuration uses a docker input plugin to interact with the docker.sock. It doesn't work, i get a permission related error:

test-grafana-telegraf3-1  | 2022-12-29T12:09:10Z E! [inputs.docker] Error in plugin: Got permission denied while trying to connect to the Docker daemon socket at unix:///docker.sock: Get "http://%2Fdocker.sock/v1.24/info": dial unix /docker.sock: connect: permission denied

Basically, the entrypoint.sh script runs telegraf (the application) with the telegraf user, which can't access the docker.sock

There's a fix for this issue described here: Telegraf can not connect to Docker sock

Issue

As i am using docker compose, i would like this fix to be defined in the compose file, and not be dependent on me starting the container with docker run.

I've tried this:

telegraf3:
  image: telegraf
  volumes:
    - ./telegraf/telegraf3.conf:/etc/telegraf/telegraf.conf
    - /var/run/docker.sock:/var/run/docker.sock:rw
  env_file:
    - ./telegraf/telegraf.env
  depends_on:
    - influxdb
  command: ["bash -c -u telegraf $$(stat -c '%g' /var/run/docker.sock)", "/entrypoint.sh"]

But then i get this error:

test-grafana-telegraf3-1  | setpriv: failed to execute bash -c -u telegraf $(stat -c '%g' /var/run/docker.sock): No such file or directory

test-grafana-telegraf3-1 exited with code 127

Max Krog
  • 181
  • 1
  • 2
  • 11
  • Also posted this to reddit: https://www.reddit.com/r/influxdb/comments/zzeywi/telegraf_docker_input_making_it_work_from_docker/ – Max Krog Dec 30 '22 at 23:29

0 Answers0