-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 does not set environment variables #7423
Comments
???
|
This is the yaml I am using. It works exactly as expected on my local machine when I don't have environment variables included. I am using docker for Windows, so the file path format is different than with linux. I have not included my PC username for privacy purposes. |
Facing the same issue. And I found that environment variables are working only from Providing environment variables from command line giving the same warnings as @Kytech mentioned. $ docker-compose run -e PRODUCT=1 all
WARNING: The PRODUCT variable is not set. Defaulting to a blank string. Providing environment variables from user-specific $ cat docker-compose.env
PRODUCT=1
RELEASE=0
FLASH=0
DEBUG=3
$ cat docker-compose.yml
version: '3'
services:
all:
image: 82100_src:latest
env_file: ./docker-compose.env
volumes:
- .:/home/user
command: make PRODUCT=${PRODUCT} all RELEASE=${RELEASE} FLASH=${FLASH} DEBUG=${DEBUG}
$ docker-compose run all
WARNING: The PRODUCT variable is not set. Defaulting to a blank string.
WARNING: The RELEASE variable is not set. Defaulting to a blank string.
WARNING: The FLASH variable is not set. Defaulting to a blank string.
WARNING: The DEBUG variable is not set. Defaulting to a blank string. I'm using Linux Debian 10 with next versions of Docker and Docker-compose: $ docker-compose version
docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.7
OpenSSL version: OpenSSL 1.1.0f 25 May 2017
$ docker version
Client: Docker Engine - Community
Version: 19.03.9
API version: 1.40
Go version: go1.13.10
Git commit: 9d988398e7
Built: Fri May 15 00:25:25 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.9
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 9d988398e7
Built: Fri May 15 00:23:57 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683 |
.env file and env_file have different semantics. If you want to use variable interpolation in your compose file you have to use the .env file. |
My conclusion here is that the -e environment variables are treated with the same semantics as env_file. Consistent with docker cli run cmd. |
@hholst80 indeed, my mistake. After reading docker documentation one more time and few additional articles, it's now obvious for me that for substitution in docker-compose file itself used environment variables of my current shell, and to send environment variables inside docker container I may use either docker run CLI or env_file. Thanks! |
@kravchenkoloznia that should be a good workaround in the meantime. I hope the docker team fixes this since it's broken just about every docker-compose file I've been using that specifies environment variables in the docker-compose.yml |
Nothing is working for me, I can't use any environment variable :
It doesn't work with env_file, .env or docker run -e either EDIT: The problem disappeared after updating docker to 18.09.8 |
Hey, While working on docker with Celery and Rabbitmq integration, I also faced the issue where the environment variables were not used up (set) though they can be seen using the env command in the container. I solved the issue by taking the below two steps.
Later on, I rechecked with the old service name and found that the issue reappeared. Then I removed the older container and again did I am using Docker Engine v19.03.12 and docker-compose v 1.26.2 The contents (related to the issue) of my docker-compose.yml are:
|
I am on the latest version of docker compose 1.27.4. I still see the same issue as other users have described above. |
I am also experiencing the same problem on the latest version of Docker (2.4.0.0). |
I have encountered the same issue, I hope this could help. It seems that by running on a different python virtual env, I ruined the docker-compose dependency pythondotenv |
I ran into this problem trying to use
This works, providing volumes associated with the resultant container are recreated (delete the volumes that the container will use and recreate) |
I have the same exact bug with the latest version of Docker 20.10 and Docker-compose 1.27 on Mac OS |
In my case only newly added one environment variable is not set in running container others get set normally.
I run printenv command inside running Linux container and verified that the Api__Recaptcha__Secret variable doesn't get set. |
This same incredibly confusing issue is occurring to me. Some of my environmental variables set in my yaml file are respected during the runtime execution, and others are missing and my runtime script validation functions terminate the container. Awkwardly, I can see all of the variables properly set in the PyCharm Environmental Variables Docker inspection. Like @namighajiyev reports above, it appears my more recent environmental variables are not being respected during runtime. I tried |
So while trying to debug this strange issue, I came up with this awkward workaround. I deleted the docker compose deployment using the docker dashboard so I can reuse the same compose definition and not have any container name conflicts. I then copied the project to another directory. Executing docker-compose up now works! So I try the aforementioned workflow again, cp the working project folder to a new home, and now docker-compose fails like previous. I am completely stumped. It seems so random. |
Had some luck by starting docker-compose in non daemon mode after a change to environment setting(via environment section in docker-compose.yml). Then stop that and start in daemon mode again, environment settings are kept. |
Any update on this? Seems that docker-compose is still not picking up .env files? |
Please give Compose v2 a try and let me know if this issue persists with the new codebase |
|
Any update on this? I have the exact same bug with Docker version 20.10.11 and Docker-compose 1.29.2 on Mac OS. Removing and re-building the containers did not help. Doesn't matter whether I |
Hello! |
@Lhamide00 @qalinn As earlier said by @ndeloof, please try using v2, so call |
Hello @ubiuser, I tried how you suggested but it didn't work. I don't have any clue what should I try. |
Hi friends, we once again encountered this mysterious error even when using |
Same here. I have the following
In my
This is to start up a flask api, but what I get when I run the container with:
or
is this:
The api insists on starting on It also does not work if I change my compose file as follows:
When running the app outside of docker it works perfectly fine. Does anyone have a sensible workaround?
|
@palunel can you check |
@ndeloof Interesting:
|
ok, so this is an application issue then :P |
Just to add my two cents as the original author if this issue, I've been able to successfully set env variables in docker compose for a little while now. Not sure what fixed it, but it seems newer versions resolved the issues I was having. |
Having similar issue right now |
Same as me, casual docker-compose, after update on windows to 4.8.1 (docker for windows) env variables are not passed to the container, even if in inspect mode these are visible... |
Experiencing this issue on Docker 20.10.17 build 100c701 on an M1 Mac. |
same build, same issue on an Intel Mac this afternoon. |
I have the same problem, using docker compose v2 |
@andremarcondesteixeira feel free to open a new issue with an example that allows us to reproduce the problem (compose file, dockerfile, try to use official images...) |
Any updates on this? Running into this today as well. Extremely unfortunate
|
Hello @gopar |
I had a similar issue, but substituting |
Any update on this ? |
|
Please also note environment variables concatenation in docker-compose is not working. Expl below, KC_HOSTPORT and KC_DUMMY can never be reused in the following environment variables (KC_COLON_HOSTPORT, KC_DUMMY2, KC_DUMMY3, ...). I tried a lot of combination. (My tech environment : Windows 11, Spring Boot, Gradle/Kotlin, Docker Desktop, IntelliJ) version: "3.8"
x-common-variables:
&common-variables
KC_HOSTNAME: localhost
KC_HOSTPORT: 8080
services:
my-backend:
environment:
<<: *common-variables
KC_PROTOCOL: http
KC_DUMMY: dummy
KC_DUMMY2: "$KC_DUMMY" #KO
KC_DUMMY3: "${KC_DUMMY}" #KO
KC_DUMMY4: "$${KC_DUMMY}" #KO
KC_COLON_HOSTPORT: ":${KC_HOSTPORT}" #KO
... |
@ihass you expect compose to replace |
Sure I will give it a try.
vinayak Phutane
…On Wed, 7 Feb 2024 at 12:10 AM, Nicolas De loof ***@***.***> wrote:
@phutaneVinayak <https://github.com/phutaneVinayak> :
Can you open a new issue with a reproducible example?
—
Reply to this email directly, view it on GitHub
<#7423 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGE5QTMWMR2VPMV4JZCXHYDYSJ2KTAVCNFSM4MYNU2XKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGA2TIMZUGYYQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This worked for me: services:
test:
image: alpine
# command: echo MYVAR=$MYVAR # Not working
# command: echo MYVAR=$$MYVAR # Not working
command: sh -c "echo MYVAR=$$MYVAR"
environment:
MYVAR: "asfd"
|
Just noting for others, |
Description of the issue
When using
docker-compose up
ordocker-compose run -e ENVIRONMENT_VAR=value
, environment variables are not being applied either through the-e
command line parameters or from the docker-compose.yml file.The docker-compose.yml file I am using is as follows:
Context information (for bug reports)
Output of
docker-compose version
Output of
docker version
Output of
docker-compose config
Steps to reproduce the issue
Observed result
Environment Variables are not applied
Expected result
Environment variables should be applied to containers started by docker-compose
Stacktrace / full error message
Additional information
OS Version: Windows 10 Pro v1909,
docker-compose
install method: Docker Desktop for Windows Installer, followed by manual upgrade of docker-compose (Issue occurred on docker-compose version 1.25.4 which was included with Docker Desktop and with manual upgrade to 1.25.5)The text was updated successfully, but these errors were encountered: