Easiest way to report container IP within env var

I need to report the container’s IP in a specific environment variable.

For example:


Is this possible?

you should use https://github.com/cloudnautique/giddyup to easily show your current ip from rancher metadata service :
giddyup ip myip will return your current ip.

hope it helps,


I’d suggest you get the IP from inside the container, using the rancher-metadata HTTP endpoint. Calling this URL from within a container will give you your 10.42 IP address:



Thank you for the suggestions. Unfortunately, none of these solve the problem of me just wanting to be able to interpolate my current ip into an env var on startup…

The IP is not known yet at the time variables are interpolated so this is not possible.

What do you want to use it for? Why do you need your IP address? As Vincent says, it isn’t known at that time. If you can let us know what you want to use the IP address for, perhaps there’s another way to get it to where it needs to be.

I have a number of containers that require me to report the IP address as an environment variable.

E.g. meteor-cluster utilizes environment variables to configure each instance of the cluster, like so.


It then places this information into a shared mongo db that acts as the centralized “discovery” resource.

So the app needs the IP inside the container. In which case, rather than starting the app (meteor?) directly inside your Dockerfile, start a small script that retrieves the IP from the http://rancher-metadata API and sticks it in the envvar that you require, before starting your app.

I’ve used this pattern successfully often.