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

Hi,

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:

172.17.0.34 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:
https://github.com/rancher/rancher/issues/5499

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

#!/bin/bash

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

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

java -jar xx.jar

exec “$@”