Dynamic env variables in a service

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!

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, /self/host/hostname.

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 ?

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