Get container Rancher IP inside a container

Inside a container running on Rancher managed network, how can I retrieve its Rancher IP?

hostname -i

gives me the “Docker IP” only.

hostname -I

Gives me both Docker and Rancher IP address, I could parse it, but is there a cleaner solution?

Thanks you,

Try this in a script, variable can be parsed further on:
ip addr | grep inet | grep 10.42 | tail -1 | awk ‘{print $2}’ | awk -F/ ‘{print $1}’

1 Like

v0.35 will contain an EC2-style metadata server which will allow a container to lookup info about itself, the service and stack it is a part of, etc. I don’t know the exact keys offhand but it will be something like



Perfect! Many thanks,

Cool feature!

Thanks you,

@ebuildy Here’s the documentation on the metadata service.