Docker Community Forums

Share and learn in the Docker community.

Telegraf in Docker-Compose

Hi there, I’m having some problems when running Telegraf in docker-compose. First I create a config directory in for telegraf in home directory (/home/ignacio/telegraf),

mkdir telegraf

Then install telegraf in a docker container using docker-compose,

cd docker-compose
nano docker-compose.yaml

Below is the code I use to create the docker container,

    container_name: telegraf
    image: telegraf
    restart: always
      HOST_PROC: /rootfs/proc
      HOST_SYS: /root/sys
      HOST_ETC: /root/etc
      - /home/ignacio/telegraf:/etc/telegraf/
      - /var/run/docker.sock:/var/run/docker.sock
      - /sys:/rootfs/sys
      - /proc:/rootfs/proc
      - /etc:/rootfs/etc
      - influxdb
      - "8092:8092/udp"
      - 8094:8094
      - "8125:8125/udp"

Finally I check the logs and get the following error,

2020-09-13T20:11:02Z I! Starting Telegraf 1.15.3

2020-09-13T20:11:02Z E! [telegraf] Error running agent: No config file specified, and could not find one in $TELEGRAF_CONFIG_PATH, /root/.telegraf/telegraf.conf, or /etc/telegraf/telegraf.conf

I think it has to do with the way I define the volumes and the directory I created. Any ideas how to fix this? I’m using docker version 3.

Thanks for your support!

it is simpler than that: you didn’t read the dockerhub description carefuly ^^

Let me quote the relevant section here:

Using a custom config file

First, generate a sample configuration and save it as telegraf.conf on the host:

$ docker run --rm telegraf telegraf config > telegraf.conf

Once you’ve customized telegraf.conf , you can run the Telegraf container with it mounted in the expected location:

$ docker run -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf

Modify $PWD to the directory where you want to store the configuration file.

Read more about the Telegraf configuration here.

1 Like