I have a script (hosted on GitHub ) that does the following:
$LOCALIP
-e LOCALIP
trying to pass the hosts environment variable to the container (I have also tried -e LOCALIP=$LOCALIP
However when I docker exec
into the container on that instance and run echo $LOCALIP
it displays nothing. Running env
shows me that LOCALIP
is there but nothing is against it
If I destroy the container and remake using the exact same line from the original script (with -e LOCALIP=$LOCALIP
) it works - I need this process automating however and some additional help would be greatly appreciated.
Essentially sudo docker run -dit -e LOCALIP -p 1099:1099 -p 50000:50000 screamingjoypad/armada-server /bin/bash
is not sharing the hosts LOCALIP
variable.
UPDATE
Trying the suggestions from below I added the following line to my script source /etc/bash.bashrc
but this still does not work. I'm still getting a blank when trying the echo $LOCALIP
in the container...
The problem is because of this line of your shell script:
echo "export LOCALIP=$(hostname -i)" >> /etc/bash.bashrc
After this command is executed, the export
instruction does not take effect yet. It will take effect after your next login.
To make the LOCALIP
environment variable take effect immediately, add this line after the echo "export ...
command:
source /etc/bash.bashrc
I believe I've solved it. I'm now using the AWS metadata to harvest the private IP address using the following addition to the script:
sudo docker run -dit -e LOCALIP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4) -p 1099:1099 -p 50000:50000 screamingjoypad/armada-server /bin/bash
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.