Get Environment Variable from Docker Container

后端 未结 10 1976
花落未央
花落未央 2020-12-12 11:12

What\'s the simplest way to get an environment variable from a docker container that has not been declared in the Dockerfile?

For instance, an environment v

10条回答
  •  抹茶落季
    2020-12-12 11:38

    @aisbaa's answer works if you don't care when the environment variable was declared. If you want the environment variable, even if it has been declared inside of an exec /bin/bash session, use something like:

    IFS="=" read -a out <<< $(docker exec container /bin/bash -c "env | grep ENV_VAR" 2>&1)
    

    It's not very pretty, but it gets the job done.

    To then get the value, use:

    echo ${out[1]}
    

提交回复
热议问题