Inside a container running on Rancher managed network, how can I retrieve its Rancher IP?
hostname -i ifconfig
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}’
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
IP=$(curl http://169.254.169.250/2015-07-25/container/ip)
Perfect! Many thanks,
Cool feature!
@ebuildy Here’s the documentation on the metadata service.
http://docs.rancher.com/rancher/metadata-service/