compose: Environment Variable is not set. Defaulting to a blank string.
A similar question has been floating around stackoverflow and github. Yet, I am not able to solve this problem, I hope somebody can point me in the right direction.
lsb_release
Distributor ID: Debian
Release: 8.8
Codename: jessie
docker-compose -v docker-compose version 1.9.0, build 2585387
docker -v Docker version 17.05.0-ce, build 89658be
/etc/environment
http_proxy=http://10.50.2.67:3128/
https_proxy=http://10.50.2.67:3128/
/etc/sudoers
...
Defaults env_keep += "http_proxy"
Defaults env_keep += "https_proxy"
...
In my docker compose, I’d like to pass both http_proxy and https_proxy as e vars.
...
web:
environment:
- http_proxy=$http_proxy
- https_proxy=$https_proxy
on docker-compose up I get
WARNING: The http_proxy variable is not set. Defaulting to a blank string.
I get the same error with any variables in env list.
What am I doing wrong?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 25
@olegstepura You can do
COMPOSE_OPTIONS="-e ENV1=$ENV1 -e ENV2=$ENV2 -e ENVn=$ENVn" docker-compose <command>@sebas5384
$PWDis a shell variable, not an environment variable. You will have to explicitly include it in the environment (e.g.PWD=$PWD docker-compose up) for it to work.@rommik 1.9.0 is pretty old as far as
docker-composegoes. Can you try upgrading to 1.14.0 and see if anything changes?My present work around is a script like this
I set
http_proxyandhttps_proxyin/etc/environmentby another process. Then, I call my script to copy them into.envand spin up my containers. This works fine, but I don’t understand why.I also have an issue with variables in
command. My test container (version 3 of compose file):Run using:
Working fine if I pass variables in
.envfile or cli:Not working if I try to set them in named env file
secrets.envor directly indocker-compose:In each scenario,
printenvis showingFOO.WARNING: The FOO variable is not set. Defaulting to a blank string.is printed even before the container was downloaded.In my case, after updating my docker-composer version to the last one (1.18.0, I was using before 1.14.0, so no suspicion of being the problem, but just in case) and being doing test for a while. Then I realized that my problem came that I have my
docker-composeinstalled as a container, so the service was trying to take the env vars from mydocker-composecontainer, not my local env vars.I have something like:
$FOOwas present on local environment (I do it in several ways), visible withprintenvand frompythonREPL but wasn’t ondocker-composecontainer.I write it down because I guess it could be enlightening for others.
@daten-kieker Are you using
docker-composewithsudo? It’s hard to imagine why Compose wouldn’t pick up your env variables.I don’t understand why someone hasn’t modified python’s variable substitution code to map
$UIDand$GIDto calls toos.getuid()andos.getgid()on POSIX hosts. Windows doesn’t have a similar concept so this wouldn’t work on windows instances of docker compose, but that would be dealing with a completely different permission model in any case.@sebas5384 In that specific example, replacing
${PWD}with.in your volume definition would work just as well.I tried reproducing the issue locally (with 1.13 as well) but it works fine for me. Did you make sure $PWD is actually defined locally (i.e. shows up
printenvoutput?) What OS are you running on?