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 V2 does not support default variable values in .env files anymore #9303

Closed
florianlink opened this issue Mar 22, 2022 · 5 comments

Comments

@florianlink
Copy link

We use docker-compose with .env files.
In the .env files, we use this syntax:

VARIABLE=${VARIABLE:-default}

which evaluates to default if VARIABLE is unset or empty in the environment in docker-compose V1.
(as described here https://docs.docker.com/compose/environment-variables/)

With V2, the VARIABLE is not set to default with this syntax.
We tested this on Windows and Linux, with Docker Compose version v2.3.3.

The default value syntax works inside of the docker-compose.yml file, but it does not work in the .env file anymore.
This used to work fine in docker-compose V1.

@ulyssessouza
Copy link
Contributor

What happens when you execute a command?
Could you please post a complete example for reproducibility?

@florianlink
Copy link
Author

compose.zip

@florianlink
Copy link
Author

I attached an example. Just run "docker-compose up" and it prints the following with docker-compose V1:

Recreating compose-test-1 ... done
Attaching to compose_test_1
test_1  | my-default-value value
compose_test_1 exited with code 0

Now when running it with docker-compose V2:

$ docker-compose up
time="2022-03-28T10:22:11+02:00" level=warning msg="The \"EXAMPLE_BAD\" variable is not set. Defaulting to a blank string."
time="2022-03-28T10:22:11+02:00" level=warning msg="The \"EXAMPLE_BAD\" variable is not set. Defaulting to a blank string."
[+] Running 1/1
 - Container compose_test_1  Recreated                                                                             0.3s
Attaching to compose-test-1
compose-test-1  | value
compose-test-1 exited with code 0

NOTE: the different between V1 and V2 is the printed warning and the missing my-default-value value of EXAMPLE_BAD env variable.

@florianlink
Copy link
Author

Any news on this?

@ulyssessouza
Copy link
Contributor

Should be fixed by compose-spec/compose-go#276 and included in the next release of Docker Compose.

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

2 participants