# Hosts hostname in docker swarm mode for telegraf

**URL:** <https://community.influxdata.com/t/hosts-hostname-in-docker-swarm-mode-for-telegraf/4912>\
**Category:** Telegraf\
**Created:** [April 26, 2018, 7:29am UTC](https://community.influxdata.com/t/hosts-hostname-in-docker-swarm-mode-for-telegraf/4912 "2018-04-26T07:29:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikki](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Mikki](https://community.influxdata.com/u/Mikki)\
**Post date:** [April 26, 2018, 7:29am UTC](https://community.influxdata.com/t/hosts-hostname-in-docker-swarm-mode-for-telegraf/4912/1 "2018-04-26T07:29:54Z")

</div>

Hello!

What would be the easiest way to get the hosts hostname to telegraf container in docker swarm mode? The stack yml can’t get the hosts hostname in swarm mode. Or if you mount the /etc/hostname to the container, how can you get that info to telegraf?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/daniel/32/142_2.png) [@daniel](https://community.influxdata.com/u/daniel)\
**Post date:** [April 26, 2018, 6:52pm UTC](https://community.influxdata.com/t/hosts-hostname-in-docker-swarm-mode-for-telegraf/4912/2 "2018-04-26T18:52:11Z")

</div>

A quick look at the os.Hostname() call in Go shows that it reads `/proc/sys/kernel/hostname`, I think it is not safe to mount the hosts `/proc` on the containers `/proc` though, so maybe it is better to set an environment variable and use that in the Telegraf config:

```auto
[agent]
  hostname = "${ENGINE_HOST}

```

Then maybe you can add this environment variable when starting the container, not sure how to do this with docker swarm but using plain docker:

```auto
 docker run -e ENGINE_HOST=$(hostname) telegraf env

```

---

<div class="post-metadata">

**Author:** ![Gcozier](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@Gcozier](https://community.influxdata.com/u/Gcozier)\
**Post date:** [May 9, 2019, 12:25pm UTC](https://community.influxdata.com/t/hosts-hostname-in-docker-swarm-mode-for-telegraf/4912/3 "2019-05-09T12:25:48Z")

</div>

Hello,

Try to following your advices , but in a swarm mode based on docker EE . I’m not able to get the hosts hostname when I’m running a telegraf container.

![image](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex023/uploads/influxdata/original/2X/a/aaaf89f78966a221e375ac854796ce6b99abd77c.png)

I tried also to map the etc/hostname and the /proc/sys/kernel/hosntame through an env variable HOSTNAME=$(cat /etc/hostname) but Influx did not interpret the bash output.

Please some one can give some feedback ?

Regards,

AY
