I ran an Alpine Docker container using the following command:
docker run -itd --env "my_env_var=test" --name mycontainer alpine
Now when I run the env command from inside the Docker container to get all the Env vars, I get the following output:
$ docker exec -it mycontainer /bin/sh
$ env
HOSTNAME=9de9045b5264
SHLVL=1
HOME=/root
my_env_var=test
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
So far, so good.
But when I try to get the Environment Variables using the docker inspect command, I see that too many ENV vars are missing (Only 2 of them are found):
$ docker inspect mycontainer
...
...
"Env": [
"my_env_var=test",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
...
...
Also, I used the docker exec command to print the ENV vars using the following command:
$ docker exec mycontainer /bin/sh -c env
HOSTNAME=9de9045b5264
SHLVL=1
HOME=/root
my_env_var=test
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
This time, all the ENV vars were displayed except for the TERM=xterm.
I observed this behaviour with centos Docker images as well. Why is it so that all the ENV vars are not getting printed using docker inspect or docker exec?