# Dynamic env variables in a service

**URL:** <https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065>\
**Category:** Rancher 1.x\
**Created:** [August 9, 2017, 1:23pm UTC](https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065 "2017-08-09T13:23:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flegaludec](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@flegaludec](https://forums.suse.com/u/flegaludec)\
**Post date:** [August 9, 2017, 1:23pm UTC](https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065/1 "2017-08-09T13:23:25Z")

</div>

Hi,  
I want to dynamically fill an environment variable when I declare a service.  
I would like to have :  
MY\_VAR = /home/$(hostname)

where $(hostname) is an environment variable already setted on the host.

Is it possible?

Thank you!

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [August 11, 2017, 2:07am UTC](https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065/2 "2017-08-11T02:07:38Z")

</div>

No. Compose supports variables but they are interpreted once on service definition, not for every host, or on the host, or in the container. You can get the current host’s hostname inside the running container from [metadata](http://rancher.com/docs/rancher/v1.6/en/rancher-services/metadata-service/#host), `/self/host/hostname`.

---

<div class="post-metadata">

**Author:** ![flegaludec](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@flegaludec](https://forums.suse.com/u/flegaludec)\
**Post date:** [August 16, 2017, 11:28am UTC](https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065/3 "2017-08-16T11:28:29Z")

</div>

Thank you Vincent.  
I can see the variable HOSTNAME inside my rancher-agent container, but I can’t see this variable inside my running container deployed with a service. Where can I see it ?

---

<div class="post-metadata">

**Author:** ![flegaludec](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@flegaludec](https://forums.suse.com/u/flegaludec)\
**Post date:** [August 16, 2017, 2:29pm UTC](https://forums.suse.com/t/dynamic-env-variables-in-a-service/7065/4 "2017-08-16T14:29:11Z")

</div>

I have found that I can curl directly the metadata container from my container. I think I can solve my problem with it now.
