Reputation: 12460
Nothing shows up for env var FOO even though I've set it:
$ docker run -e FOO=foofoo ubuntubr echo $PATH
/bin:/usr/ucb:/usr/bin:/usr/sbin:/sbin:/usr/etc:/etc
$ docker run -e FOO=foofoo ubuntubr echo $FOO
$
What did I do wrong?
But I was able to modify the path:
docker run -e PATH=/nopath ubuntubr echo $PATH
docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"echo\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled
Then why isn't docker run -e FOO=foofoo ubuntubr echo $FOO
isn't printing foofoo
?
Upvotes: 2
Views: 1369
Reputation: 25250
The variables are set. The way you are trying to verify that they are set is wrong.
It's called "variable expansion" and I quote from the answer @larsks has given here:
$ docker run -it alpine echo $HOME
/home/lars
$ docker run -it alpine echo '$HOME'
$HOME
$ docker run -it alpine sh -c 'echo $HOME'
/root
$HOME
variable of your host, not the container's. In your case $FOO
doesn't exit on the host, so it prints an empty line$HOME
(like a string)$HOME
variable of the containerExample for your case:
$ docker run -e FOO=foofoo alpine sh -c 'echo $FOO'
foofoo
Thanks @vmonteco for pointing out docker inspect
for debuging. If you want to learn more on what your containers were actually doing, below are the CMD
set for the 3 different cases discussed previously:
"Cmd": ["echo"]
"Cmd": ["echo","$FOO"]
"Cmd": ["sh","-c","echo $FOO"]
Upvotes: 5