I am learning Docker and facing issue in substituting the value of one env variable into another env variable.
This is my Dockerfile
FROM ubuntu
ENV var_env=Tarun
ENV command="echo Hello $var_env"
CMD ["sh","-c","echo Hello $var_env"]
Now, after building it with tag name "exp", then
sudo docker run -e "var_env=New Env Value" exp
It gives me correct output as
Hello New Env Value
But, if I see the environment variables associated by executing
sudo docker run -e "var_env=New Env Value" exp env
It gives me this output:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=138aa8852d8d
var_env=New Env Value
command=echo Hello Tarun
HOME=/root
In it, the value of var_env environment variable is changed and value of command environment variable remains same.
I need to find a way so that if I change the value of var_env environment variable by the above command, it will update the value of var_env environment variable inside command environment variable also.
For reference: https://docs.docker.com/engine/reference/builder/#environment-replacement