# Best way to determine either device name or host name in a container

**URL:** <https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191>\
**Category:** Product support\
**Created:** [May 20, 2018, 10:44pm UTC](https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191 "2018-05-20T22:44:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dblaise](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@dblaise](https://forums.balena.io/u/dblaise)\
**Post date:** [May 20, 2018, 10:44pm UTC](https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191/1 "2018-05-20T22:44:27Z")

</div>

I’m trying to map a naming convention against my devices. When flashing all of them I specified a “hostname” on the config.json which would be their unique identifiers. My Node application then grabs the hostname and identifies itself to my external server. However, it seems that docker is detecting and using the container hostname ie. `odroid-xu4-1d6259c`.

Wondering what would be easiest/best way to handle this? My understanding is that the RESIN\_HOST\_CONFIG\_\* variables are available container side. Within my Node application how can I gain access to this value?

**UPDATE:** I’ve learned that I can use `resin device rename` to change the device name. So rather than depend on hostname I’m going to use the device name from Resin. So to revise my question, how can I easily snag the device name of from within my Node app (running inside the container?).

Thanks!

---

<div class="post-metadata">

**Author:** ![spanceac](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@spanceac](https://forums.balena.io/u/spanceac)\
**Post date:** [May 21, 2018, 12:28pm UTC](https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191/2 "2018-05-21T12:28:02Z")

</div>

Hi dblaise,

Device’s name is contained in the following environment variable: RESIN\_DEVICE\_NAME\_AT\_INIT.

You can read in your application the value of the variable.

From the shell you can see it with this command:  
echo $RESIN\_DEVICE\_NAME\_AT\_INIT

Regards!

---

<div class="post-metadata">

**Author:** ![dblaise](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@dblaise](https://forums.balena.io/u/dblaise)\
**Post date:** [June 17, 2018, 10:49pm UTC](https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191/3 "2018-06-17T22:49:12Z")

</div>

Hi @spancea ,

Coming back to this issue, it seems like whenever I run `echo $RESIN_DEVICE_NAME_AT_INIT` within terminal on the device, it returns an empty string/line carriage and obviously not the correct hostname.

Also I’m wondering if this same variable is accessible WITHIN the application container itself? For example if I were to pass it into my Node environment like so, should I not see the follow?

`DEVICE=$RESIN_DEVICE_NAME_AT_INIT node server.js`

Thanks in advance,

David

---

<div class="post-metadata">

**Author:** ![floion](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@floion](https://forums.balena.io/u/floion)\
**Post date:** [June 24, 2018, 8:26am UTC](https://forums.balena.io/t/best-way-to-determine-either-device-name-or-host-name-in-a-container/3191/7 "2018-06-24T08:26:34Z")

</div>

Hi,

> RESIN\_DEVICE\_NAME\_AT\_INIT

is available **only** in the container. So you should be able to use it anyway you would use any other variable in your container
