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 does not handle variable defaults in --env-file (docker-compose does) #8519

Closed
jj-meyer opened this issue Jul 7, 2021 · 8 comments

Comments

@jj-meyer
Copy link

jj-meyer commented Jul 7, 2021

Description
Variables defaults declared in the --env-file are not passed to a compose-file.

$ docker compose version
    Docker Compose version 2.0.0-beta.5

$ docker-compose --version
    docker-compose version 1.29.2

Steps to reproduce the issue:

  1. Create ./foo.yml compose-file in the project-directory
services:
  nginx:
    build:
      context: .
      args:
        - FOO=${FOO}
    environment:
        - BAR=${BAR}
  1. Create ./foo.env environment file
FOO="${FOO:-FOO_ENV_DEFAULT}"
BAR="${BAR:-BAR_ENV_DEFAULT}"

The Project folder should contain ...

./foo.yml
./foo.env

Describe the results you received:

  1. docker compose fails - FOO and BAR defaults are not substituted correctly when passed into foo.yml
$ docker compose --project-directory . --env-file foo.env --file foo.yml config

...

services:
  nginx:
      args:
        FOO: :-FOO_ENV_DEFAULT} ❌
    environment:
      BAR: :-BAR_ENV_DEFAULT} ❌

  1. docker compose with foo.yml and declared environment variables succeeds
$ FOO="FOO_ENV_CMDLINE" BAR="BAR_ENV_CMDLINE" docker compose --project-directory . --env-file foo.env --file foo.yml config

...

services:
  nginx:
      args:
        FOO: FOO_ENV_CMDLINE ✅
    environment:
      BAR: :-BAR_ENV_CMDLINE ✅

  1. docker-compose succeeds - FOO and BAR variables are passed correctly
$ docker-compose --project-directory . --env-file foo.env --file foo.yml config

...

services:
  nginx:
    build:
      args:
        FOO: FOO_ENV_DEFAULT ✅
    environment:
      BAR: BAR_ENV_DEFAULT ✅

Describe the results you expected:
Variable defaults declared in the --env-file should be passed to a compose-file.

This works correctly when the environment variables are declared and when docker-compose (Python version) is used.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

$ docker --version
    Docker version 20.10.7, build f0df350

$ docker compose version
    Docker Compose version 2.0.0-beta.5

$ docker-compose --version
    docker-compose version 1.29.2, build 5becea4c
@jj-meyer
Copy link
Author

jj-meyer commented Jul 7, 2021

Although not the same result, it may be that #1892 can be related to the same .env variable handling issue.

@ndeloof
Copy link
Contributor

ndeloof commented Jul 12, 2021

root cause is that the godotenv library we use to parse .env file does not support the ${*:-*} syntax for default variable values.

Would need to improve https://github.com/joho/godotenv/blob/ddf83eb33bbb136f62617a409142b74b91dbcff3/godotenv.go#L330

@ndeloof
Copy link
Contributor

ndeloof commented Jul 12, 2021

internally tracked as https://docker.atlassian.net/browse/IL-393

@charlesritchea
Copy link

I didn't see an already open ticket for godotenv so I created one joho/godotenv#153

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@phillipuniverse
Copy link

This is not stale and is still an active issue in V2 of Docker Compose.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as not stale anymore due to the recent activity.

@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
Projects
None yet
Development

No branches or pull requests

6 participants