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

docker-compose doesn't use env_file #4001

Closed
agordeev opened this Issue Oct 4, 2016 · 7 comments

Comments

Projects
None yet
5 participants
@agordeev
Copy link

agordeev commented Oct 4, 2016

$ docker-compose version
docker-compose version 1.8.1, build 878cff1
docker-py version: 1.10.3
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013

Here's how my docker-compose.yml file looks like:

parse-server:
  image: 94fc5293168d
  restart: always
  env_file: config.env
  ports:
    - "1337:1337"
  environment:
    PORT: 1337
    DATABASE_URI: $DATABASE_URI
    APP_ID: $APP_ID
    MASTER_KEY: $MASTER_KEY
 ......

However, when I run docker-compose up -d, Compose doesn't expose variables from config.env to environment variables.

Curious, when I remove env_file: config.env and rename config.env to .env, everything works just fine.

PS: env_file: ./config.env doesn't work either.

@robertaistleitner

This comment has been minimized.

Copy link

robertaistleitner commented Oct 4, 2016

I think that's exactly the behaviour the environment variable documentation describes. If you want to use the environment variables from config.env inside of the docker-compose.yml file, you have to use the .env file.

The way you're using the env_file parameter passes environment variables directly to the Dockerfile, where you can use them.

Please correct me if I'm wrong.. ;)

@agordeev

This comment has been minimized.

Copy link
Author

agordeev commented Oct 4, 2016

@robertaistleitner Looks like you right. Can anybody confirm this?
If env_file and .env are unrelated, it confuses people. See this:

The docs say you can specify you're own env-file or even multiple files, however I could not get that working. It always wanted to choose the .env file.

http://staxmanade.com/2016/05/how-to-get-environment-variables-passed-through-docker-compose-to-the-containers/

@shin-

This comment has been minimized.

Copy link
Contributor

shin- commented Oct 4, 2016

Environment variables have become unfortunately loaded and ambiguous when dealing with Compose. This is why we recently added a disambiguation page to our documentation that should help with those cases. If you have any suggestion to improve it however, we gladly welcome pull requests.

To summarize:

  • Variable substitution in your docker-compose.yml file will be pulled (in decreasing order of priority) from your shell's environment and your .env file.
  • Variables available in your container are a combination of values found in your env_file files and values described in the environment section of the service.
  • Those are two entirely separate sets of features.

HTH.

@argast

This comment has been minimized.

Copy link

argast commented Oct 14, 2016

Are there any plans to allow specifying variable values in docker-compose command line?

@robertaistleitner

This comment has been minimized.

Copy link

robertaistleitner commented Oct 15, 2016

You can easily add environment variables by defining them before the docker-compose command like this
ENVVAR=ENVVAL docker-compose up

@argast

This comment has been minimized.

Copy link

argast commented Oct 16, 2016

@robertaistleitner: That's very useful, thanks for sharing it.

@matthias-p-nowak

This comment has been minimized.

Copy link

matthias-p-nowak commented Feb 27, 2019

The use is as a list, not just 1 file:

my-service:
  env_file:
    - <env file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.