Get Environment Variable from Docker Container

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 variable that has been set through some docker exec container /bin/bash session?

I can do docker exec container env | grep ENV_VAR, but I would prefer something that just returns the value.

I’ve tried using docker exec container echo "$ENV_VAR", but the substitution seems to happen outside of the container, so I don’t get the env var from the container, but rather the env var from my own computer.

Thanks.

10 Answers
10

Leave a Comment