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 are not applied on container build #1837
Comments
This is expected. The This is maybe not obvious from the documentation and could be improved. Docker doesn't support injecting environment into the build environment (it must be part of the Dockerfile), but I believe there are some open proposals to add support for something like that. |
Just a reference for anyone who find this issue, here is docker discussion regarding build-time variables: moby/moby#14634 and corresponding PR: moby/moby#15182 |
This bit us hard, really needs better docs. |
The documentation is really confusing, e.g. talks about env-file, which is used for |
Bit me as well. |
Updated docs in #3747 |
Note that if you need to include env vars from a file, you can do the following. This will require (in the docker-compose build section) args set from these variables, which you can then refer to in your docker file. This means that while you can't directly reuse your env_file, you can do so with a little extra work.
|
the answer to this stack overflow question helped https://stackoverflow.com/questions/19537645/get-environment-variable-value-in-dockerfile it is possible to map the .env environment variables to ARGS to be used by the Dockerfile during build.
|
@williamli Can you add a link to the Stack Overflow question? |
Sorry guys - I am not sure I understand how to resolve this - and I would like to use a pre-built image. For example, my compose file is:version: '3' services:
I used to think that the api image (softwaremaker/api-w) will be able to resolve into the environment variables I had set up above but it doesnt work. |
@PatrLind https://stackoverflow.com/questions/19537645/get-environment-variable-value-in-dockerfile |
The issue is still relevant for env files other than default
while SERVER_NAME is defined in second env file ( |
@remort My solution for this during my build copying the other named env file and renaming it to .env COPY .env.docker ${APP_HOME}/.env
WORKDIR $APP_HOME After this it appeared to pickup the environment variables when the container runs Operating System: macOS (10.14.6) |
Hi guys, A quick question for all of you, will this be a better way to build an image for dev? It works fine so far. However, is this the recommended practice? All images are based on buster.
|
Problem is still exists.
Because i am using shell scripts to build and up docker compose. |
I think there needs to be some elegant way around this. I really like the docker syntax and using arguments instead of environment variables doesn't make sense to me. I would not want want someone to manually change my docker-compose files. Changing values in the .env files appears consistent to me. |
This seems still haven't been fixed. I've spent today about 5 hours trying to figure this out. I've tried basically to use |
Same here |
Some containers will have environment variables passed to them, some will not. Redis seems to be one of those containers that won't. At the moment this is the only container in my compose file (that I'm aware of) that seems to just flat-out ignore the environment file. Every other container where I'm using this strategy works fine.
|
Funny to see this is over 8 years old at this point. Seems like bread and butter stuff I am doing but can't figure out what else I should be doing...
As you can see, it doesn't matter where I define the build args, seems they can't be used in a FROM statement either way. |
When building container, environment variables are not applied.
docker-compose.yml:
/img/Dockerfile:
Expected to have "Hello" written, received
KeyError: VAR
- missing environment variable.If you get into container with
docker-compose run --rm img bash
(after removing that last failing line) and dopython -c 'import os; print os.environ["VAR"]'
you will get expected result.docker-compose==1.3.3
docker-version
:The text was updated successfully, but these errors were encountered: