Id like a container to have a simple way to access the agents hostname.
either by having the hostname of the container set as the agents hostname or accessible via an environment variable.
the preferred place to do this:
io.rancher.container.hostname_override (this currently only supports container_name)
There are a couple of special variables currently ${{stack_name}} ${{service_name}}
I cannot find any more special variables like this but perhaps that would be the perfect thing to expand on and document.
Theres a couple of ways to get around this current limitation:
- give the container network host instead of managed
- mount /etc/hostname in the container then have an entrypoint script scrape it
- other horrible more privilege escalation
Why do you want this? What do you want to use it for? There might be another way of achieving what you’re aiming at.
You can get a lot using the rancher metadata service (http://rancher-metadata) from inside the VM. Use http://rancher-metadata/2015-12-19/self to find out stuff about your own host, or just http://rancher-metadata/2015-12-19 to see what else you can find out.
Sorry for the delay, to be honest this had slipped my mind
My use case for this is pretty simple:
- Run a container on each agent that does fluentd logging, with the log_drivers you do not get the docker host the even came from so you need to add it
- This means that the container needs to know which host its on to log the event.
I ended up just making that container have ‘host’ networking. which then means if i get the hostname its of the agent its running on.
Reasons to avoid the rancher-metadata service for this is because then the image is not portable to anything else.