0

I have set some environment variables(available only at runtime not known while creating container) in a running docker container as I explained here

Now when I go inside the container and run 'set' command I can see the environment variables but 'env' command does not show the variables I set using script.

Now I want to read the environment variables from the host machine using a script. My script is as below-

#!/bin/bash

set > envVariableList

But after successful execution of the script inside container 'envVariableList' file does not contain the environment variables I set after starting the container. The confusion here is, output of 'set' command in bash shell contains the environment variables but 'set' command in script gives different output to 'envVariableList' file. why? FYI: The script is run as 'root' inside container.

Can anyone please help me to read the custom environment variables set inside container from host machine?

Community
  • 1
  • 1
zaman sakib
  • 851
  • 11
  • 18
  • 1
    There must be some problem with your script. If I run a container with `--env var=val` I can see that value inside the file when I do `set > envVariableList`. Are you sure you're making your environment variables persistent for all the system and not only the shell executing the script? – Alexander George Jan 11 '17 at 14:48
  • @AlexanderGeorge- As I already mentioned in my question that I do not create variables with '--env' while creating the container. I set the environment variable in a running docker container by souring '/etc/bash.bashrc' file. I am not sure this makes it persistent all the system or not. However output of 'set' command inside container gives my desired variables. But inside container 'set' command output and 'set > envVariableList' command in script has different output. Any idea why? – zaman sakib Jan 11 '17 at 15:44
  • Try adding the variables to your `.bash_profile`, not only `bash.bashrc`. – Alexander George Jan 11 '17 at 15:48

0 Answers0