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

**URL:** <https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170>\
**Category:** Telegraf\
**Tags:** influxdb, telegraf, docker\
**Created:** [June 1, 2021, 12:03pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170 "2021-06-01T12:03:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![t481](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/t481/32/6012_2.png) [@t481](https://community.influxdata.com/u/t481)\
**Post date:** [June 1, 2021, 12:03pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/1 "2021-06-01T12:03:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ravikant\_Gautam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ravikant_gautam/32/5700_2.png) [@Ravikant\_Gautam](https://community.influxdata.com/u/Ravikant_Gautam)\
**Post date:** [June 1, 2021, 12:30pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/2 "2021-06-01T12:30:08Z")

</div>

you can `secrets.env` file that should contain  
`token=token_string`  
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.

---

<div class="post-metadata">

**Author:** ![t481](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/t481/32/6012_2.png) [@t481](https://community.influxdata.com/u/t481)\
**Post date:** [June 1, 2021, 2:21pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/3 "2021-06-01T14:21:44Z")

</div>

> [@Ravikant\_Gautam](#):
>
> secrets.env

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

---

<div class="post-metadata">

**Author:** ![Ravikant\_Gautam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ravikant_gautam/32/5700_2.png) [@Ravikant\_Gautam](https://community.influxdata.com/u/Ravikant_Gautam)\
**Post date:** [June 1, 2021, 2:29pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/4 "2021-06-01T14:29:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![t481](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/t481/32/6012_2.png) [@t481](https://community.influxdata.com/u/t481)\
**Post date:** [June 1, 2021, 3:19pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/5 "2021-06-01T15:19:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ravikant\_Gautam](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ravikant_gautam/32/5700_2.png) [@Ravikant\_Gautam](https://community.influxdata.com/u/Ravikant_Gautam)\
**Post date:** [June 1, 2021, 3:24pm UTC](https://community.influxdata.com/t/telegraf-docker-container-and-env-file-etc-default-telegraf/20170/6 "2021-06-01T15:24:10Z")

</div>

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.

```
 env_file:
          - secrets.env
```
