How to add env param?

Before rancher, I create docker container with the script:
docker run --shm-size=1G --cap-add NET_ADMIN --privileged=true -v /home/oj/data:/home/oj/data -v /home/soft:/home/soft -v /home/oj/log:/home/oj/log -v /home/oj/etc:/home/oj/etc -p 2222:22 --restart=always --name=oj2 –env hostip=`ifconfig eth0 | awk ‘/inet addr:/{print $2}’ | awk -F: ‘{print $2}’` -it --entrypoint=/home/soft/ojdaemon docker.acmcoder.com/oj:latest /home/oj 1

In the container, I want to use env param hostip, and the value of it is the host eth0’s ip address.

When I create a service in rancher, I add the env param like this: hostip=`ifconfig eth0 | awk ‘/inet addr:/{print $2}’ | awk -F: ‘{print $2}’`
In the container, when I echo $hostip, It displays `ifconfig eth0 | awk ‘/inet addr:/{print $2}’ | awk -F: ‘{print $2}’`, not the host eth0’s ip address.

How to pass a shell script result to the env value?

you can do that in entrypoint script. Evaluate your ip address and set it as an environment variable in the script.

what OS are you using?

You can get the IP of the host you’re running on from metadata, but you cannot do something like what you’re showing. That only works because you’re in a shell on the target host and letting it interpret that. The Rancher (or Docker Remote) API does not shell-interpret values.

my os version is Ubuntu 14.04

I want to get the host computer’s ip address, but not the container’s ip address. How to get the host machine’s ip address in entrypoint script.

For example, I have 100 machines in the cloud, and I can get the host list of these machines as follows:
Internet IP Address, Intranet IP Address, Instance ID/Name
47.93.81.28, 10.30.136.49, oj1
47.93.81.29, 10.30.136.50, oj2

When I run one container on each machines, the daemon process on each container tell the db server his unique id. So I can monitor each daemon process’s running data. But how to know who is the host of daemon process from a unique id? When daemon process use ip address as his unique id, it just like this: 10.42.88.53, 10.42.88.54. It’s the container’s ip address, but not the host’s ip address, so I can’t map to the host list provided by cloud platform.

Can you give me a solution? Thanks.