Telegraf Docker Container and env file (/etc/default/telegraf)

Hello all,
I am struggling to get my Telegraf:latest container to load up the InfluxDB v2.0 token from /etc/default/telegraf. If I run docker exec -it telegraf /bin/bash I can cat /etc/default/telegraf and it contains the token (it is mounted in the docker-compose.yml file). I am referencing that variable INFLUXDB_TOKEN in the telegraf.conf file as token="${INFLUXDB_TOKEN}" but it doesn’t seem to load. I know that because when I replaced the variable in the .conf file with the actual token it works fine.

Any ideas would be greatly appreciated.

p.s. I tried token="$INFLUXDB_TOKEN" without the curly brackets to no avail.

you can secrets.env file that should contain
reference this into your telegraf.conf and it will work fine.

Note: for the first time when you will run the container for InfluxDB create the token in InfluxDB UI and copy-paste the same token in the secrets.env file and again bring down the container and bring up again and it will work.

I am doing the same for my stack.

Thanks @Ravikant_Gautam. Do you create the secrets.env file in the same directory as the telegraf.conf file? Is this a docker thing, Telegraf or telegraf docker container thing?

Thank you for your help. I hope I manage to get this to work

I kept secrets.env where I kept my docker-compose.yml file.

How did you “tell” Telegraf where to get the variable from?

wherever you have use the token variable just pass “${TOKEN}”
just TOKEN=token_string in your secrets.env file and mention this in your docker-compose.yml file.

          - secrets.env