-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Support for Required Environment Variables #4493
Labels
Comments
eliat123
pushed a commit
to eliat123/compose
that referenced
this issue
Apr 25, 2017
eliat123
pushed a commit
to eliat123/compose
that referenced
this issue
Apr 25, 2017
eliat123
pushed a commit
to eliat123/compose
that referenced
this issue
Apr 28, 2017
eliat123
pushed a commit
to eliat123/compose
that referenced
this issue
Apr 28, 2017
Fixed by #5531 |
Why I can't find that information in the official documentation (link)? |
If you just click on the link, you'll find it. |
Thank you @shin- 🤘 ✌️ |
In 2024, link is: https://docs.docker.com/compose/compose-file/12-interpolation/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm creating a new request for specifying required environment variables in docker-compose.yml. This applies to both env vars used for variable substitution, and also for those passed to containers in the
environment
block. This has been asked for in the past ( see #2441 and #1377), but issues have been closed without addressing this. @dnephin 's implementation of default environment variables via:-
suffix is the closest thing to what a required variable implementation would look like.Variable Substitution
Current Behavior
Environment variables used for variable substitution (ie:
${ENV_VAR}
) in docker-compose.yml are currently replaced with a blank string at runtime if they are not set. Compose throws a warning but continues running the container.Proposal
Allow users to specify environment variables that must be set and can not be empty by appending the variable with suffix
?
. This maintains backwards compatibility with current ENV VAR naming implementation (current ENV VARS keys can not contain '?'). The container would not run unless this variable was set via.env
or exists and is not empty on the host.Example:
Note: Specifying a default/fallback ENV VAR value via
$VAR:-default
should not be allowed in combination with the "required" suffix. The "required" suffix throws an error on empty vars, while the "default" suffix catches empty vars and replaces them with the default. The two cannot not be combined.Environment Block
Current behavior
When a key with no value is placed in the
environment:
block (orenv_file
), compose inherits that variable from the host. If the variable does not exist on the host, the variable is not set and is not passed to the container, and no warnings are thrown. The container runs without the environment variable.Proposal
Allow users to specify required environment variables in the
environment
block (orenv_file
), throwing a runtime error at container startup if any required vars are empty or do not exist.Example:
Work Needed
I'm basing this off of @dnephin 's implementation of default environment variables. I'm not sure yet how to implement similar in the
environment
block.interpolation.py
will need to parse the suffix?
as a "required and not empty" flag. Regex will look something like this regex for the default env var suffix.The text was updated successfully, but these errors were encountered: