Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable is not set. Defaulting to a blank string. #5003

Closed
rommik opened this issue Jul 6, 2017 · 25 comments
Closed

Environment Variable is not set. Defaulting to a blank string. #5003

rommik opened this issue Jul 6, 2017 · 25 comments

Comments

@rommik
Copy link

rommik commented Jul 6, 2017

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?

@shin-
Copy link

shin- commented Jul 7, 2017

Do you see http_proxy in the output of printenv?

@rommik
Copy link
Author

rommik commented Jul 10, 2017

@shin- correct, I can see it in the output of printenv.

XDG_SESSION_ID=4
SHELL=/bin/bash
TERM=cygwin
OLDPWD=/root
http_proxy=10.50.0.137:3128
USER=root
SUDO_USER=root
SUDO_UID=0
USERNAME=root
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/usr/local/bin/docker
LANG=en_US.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/su root
HOME=/root
HTTP_PROXY=10.50.0.137:3128
LOGNAME=root
SUDO_GID=0
_=/usr/bin/printenv

I tried to capitalize it as well, just in case.

@rommik
Copy link
Author

rommik commented Jul 10, 2017

My present work around is a script like this

#!/bin/bash
cp /etc/environment .env
docker-compose up -d --remove-orphans --force-recreate

I set http_proxy and https_proxy in /etc/environment by another process. Then, I call my script to copy them into .env and spin up my containers. This works fine, but I don't understand why.

@shin-
Copy link

shin- commented Jul 10, 2017

Yeah, it should work fine. If you open a python REPL and execute import os; print os.environ, is http_proxy present in the output as well?

@rommik
Copy link
Author

rommik commented Jul 10, 2017

Yes, I see them too

Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os;
>>> print os.environ;
{'USERNAME': 'root', 'LANG': 'en_US.UTF-8', 'TERM': 'cygwin', 'SHELL': '/bin/bash', 'SUDO_COMMAND': '/bin/su root', 'SHLVL': '1', 'OLDPWD': '/root', 'http_proxy': '10.50.0.137:3128', 'SUDO_
UID': '0', 'HTTP_PROXY': '10.50.0.137:3128', 'PWD': '/usr/local/bin/docker', 'LOGNAME': 'root', 'USER': 'root', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME
': '/root', 'MAIL': '/var/mail/root', 'SUDO_USER': 'root', 'XDG_SESSION_ID': '4', 'SUDO_GID': '0', '_': '/usr/bin/python'}
>>>

@sebas5384
Copy link

I'm having the same issue, a variable like $PWD isn't being catch by the docker-compose.yml file.

@rommik
Copy link
Author

rommik commented Jul 10, 2017

I updated my compose and docker info in the original question, if it helps

@shin-
Copy link

shin- commented Jul 10, 2017

@sebas5384 $PWD is 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-compose goes. Can you try upgrading to 1.14.0 and see if anything changes?

@rommik
Copy link
Author

rommik commented Jul 10, 2017

@shin- wow! I should have started with that . Thanks :) it is the version of compose file....! 1.14.0 works as expected.

@sebas5384
Copy link

@shin- Didn't work either, even passing the variables like you said.

docker@baleia:~/project-fsi$ PWD=$PWD docker-compose -f docker-compose.dev.yml up
WARNING: The PWD variable is not set. Defaulting to a blank string
version: '2.2'

services:
  database:
    image: mysql:5.6
    container_name: 'project-fsi-db'
    volumes:
      - ${PWD}/.mysql/:/var/lib/mysql
docker-compose version 1.13.0, build 1719ceb
Docker version 17.06.0-ce, build 02c1d87

I can't understand what is happening, why a variable like $HOME for example is working but the others doesn't.

@shin-
Copy link

shin- commented Jul 10, 2017

@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 printenv output?) What OS are you running on?

@sebas5384
Copy link

@shin- the problem is that I need to load other variables to the docker-compose file.

Yes! they are, all the variables are defined and listed in the printenv.
We are using Ubuntu Server:

Linux version 4.4.0-83-generic (buildd@lgw01-29) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

We are doing a workaround re-declaring the variables into the .env, but this isn't what we would like to do since each environment has it's own PWD, etc...

BTW: thanks for your help ;)

@jhereth
Copy link

jhereth commented Jul 27, 2017

I observe the same problem as @sebas5384 , running docker-compose 1.14 on MacOS against docker 1.12 running in a virtualbox (Ubuntu Trusty).

The .env file approach works, environment variables are ignored (though visible in os.environ in a python environment).

@shin-
Copy link

shin- commented Jul 27, 2017

@daten-kieker Are you using docker-compose with sudo? It's hard to imagine why Compose wouldn't pick up your env variables.

@jhereth
Copy link

jhereth commented Jul 28, 2017

@shin- No, no sudo, nothing fancy.

@unstephenk
Copy link

I am having the same issue. any updates on this?

@jimmyharris
Copy link

I don't understand why someone hasn't modified python's variable substitution code to map $UID and $GID to calls to os.getuid() and os.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.

@Jastrzebowski
Copy link

Jastrzebowski commented Aug 22, 2017

I also have an issue with variables in command. My test container (version 3 of compose file):

container:
    image: debian
    command: echo ${FOO}

Run using:

docker-compose up --remove-orphans --force-recreate container

Working fine if I pass variables in .env file or cli:

FOO=cli docker-compose up --remove-orphans --force-recreate container

Not working if I try to set them in named env file secrets.env or directly in docker-compose:

container:
    image: debian
    command: echo ${FOO}
    env_file: secrets.env
    environment:
      FOO: bar

In each scenario, printenv is showing FOO. WARNING: The FOO variable is not set. Defaulting to a blank string. is printed even before the container was downloaded.

docker-compose version 1.14.0, build c7bdf9e
Docker CE Version 17.06.0-ce-mac19 (18663)

@barraquito
Copy link

barraquito commented Jan 10, 2018

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-compose installed as a container, so the service was trying to take the env vars from my docker-compose container, not my local env vars.

I have something like:

service:
    environment:
        FOO

$FOO was present on local environment (I do it in several ways), visible with printenv and from python REPL but wasn't on docker-compose container.

I write it down because I guess it could be enlightening for others.

@olegstepura
Copy link

@barraquito so how to pass an ENV variable if you are using docker-compose installed as a container? I just realized the same as you did but have no idea how to fix this.

@barraquito
Copy link

@olegstepura in my case, after a first quick research didn't find how to pass the ENV variable to the docker-compose container, so I just installed it without a container. I couldn't research more about that, sorry.

@olegstepura
Copy link

olegstepura commented Mar 20, 2018

That might be an issue to docker-compose since docker-compose running in container is one of the official ways of running docker-compose. @shin- what would you say?

@shin-
Copy link

shin- commented Mar 20, 2018

@olegstepura You can do COMPOSE_OPTIONS="-e ENV1=$ENV1 -e ENV2=$ENV2 -e ENVn=$ENVn" docker-compose <command>

@stale
Copy link

stale bot commented Oct 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 9, 2019
@stale
Copy link

stale bot commented Oct 17, 2019

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants