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 variables from "env_file" directive are not available during build #1901

Closed
jportner opened this issue Aug 21, 2015 · 3 comments
Closed

Comments

@jportner
Copy link

This StackOverflow post describes my issue well: http://stackoverflow.com/questions/31210197/how-to-make-environmental-variables-available-to-docker-run-commands-from-docker

I'm trying to set environment variables within docker-compose.yml via the "env_file" directive.
I've got my environment variables (such as http_proxy, etc.) but those variables aren't available until after the Docker container is built.
Ideally, those environment variables would be set before the Docker container starts to build, so commands such as "RUN apt-get install package" would have access to them (and be affected by them, as is the case with http_proxy)

I think this is a reasonable request, but is it even possible to implement with the way docker-compose is written?

@dnephin
Copy link

dnephin commented Aug 21, 2015

This is a restriction imposed by the docker engine, not compose, and it's by design. If you have environment variables external to the Dockerfile, then your build is not repeatable with just the Dockerfile + build context.

If you wanted to, you could do something like this in the Dockerfile

ADD env_file /build/env file
RUN some-script-that-sources-env_file-and-does-other-work.sh

@thaJeztah
Copy link
Member

Actually, there's WIP in Docker to have build-time variables; see moby/moby#15182

NOTE: please do NOT comment on the linked pull-request, unless you've got something substantial to add, if you want to stay up to date, use the "subscribe" button on the PR

Previous PRs for that feature ended up in endless non-related comments, resulting in the PR being closed. See moby/moby#9176 and moby/moby#14634 for history

@jportner
Copy link
Author

jportner commented Sep 3, 2015

Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants