Get Environment Variable from Docker Container
The proper way to run echo "$ENV_VAR"
inside the container so that the variable substitution happens in the container is:
docker exec <container_id> bash -c 'echo "$ENV_VAR"'
To view all env variables:
docker exec container env
To get one:
docker exec container env | grep VARIABLE | cut -d'=' -f2
You can use printenv VARIABLE
instead of /bin/bash -c 'echo $VARIABLE
. It's much simpler and it does not perform substitution:
docker exec container printenv VARIABLE