Get the ip 10.xx instead of 172.xx in container from RPC program


I have a RPC program written in Java, which will get the ip from eth0. But according to rancher’s networking rule, there are two ips(172.xx and 10.xx) assigned to eth0. Then the RPC program(I can’t modify it) will get the first ip(172.xx) to expose service for other containers(container even in another host). The other containers can ping 10.xx, but fail ping to 172.xx.

I have checked the /etc/hosts, the ip is also 172.xx likes: container_id

Is there any way that i can change the ip from 172.xx to 10.xx in /etc/hosts by configuration, or change the ip order of eth0?

Any way can change /etc/hosts from Rancher UI?
Same issue as:

I found a solution to obtain the rancher managed ip by using In the,we can the container’s primary ip(10.42.x.x) and hostname, then rewrite them to /etc/hosts. All works fine, code likes:


CONTAINER_IP=$(curl http://rancher-metadata/latest/self/container/primary_ip)

echo “ localhost” > /etc/hosts
echo “$CONTAINER_IP $CONTAINER_NAME” >> /etc/hosts

java -jar xx.jar

exec “$@”