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

default values for environment variables? #6914

Closed
waltertross opened this issue Jun 20, 2018 · 9 comments
Closed

default values for environment variables? #6914

waltertross opened this issue Jun 20, 2018 · 9 comments
Labels
area/compose Relates to docker-compose.yml spec or docker-compose binary lifecycle/locked

Comments

@waltertross
Copy link

waltertross commented Jun 20, 2018

File: compose/environment-variables.md
How to declare default values for environment values substitution in situations where the .env file cannot be used?

@joaofnfernandes
Copy link
Contributor

joaofnfernandes commented Jun 20, 2018

If I understand your question correctly, you can use shell parameter substitution.

Your compose file would look like:

version: '3.1'

services:
  lb:
    image: nginx:latest
    environment:
      PASSWORD: "${PASS:-secret}"

In the container, set $PASSWORD with the value of $PASS or default to secret. Then you could use:

PASS=super-secret docker-compose -f docker-compose-2.yml up

Please consider filing a pull request to improve the docs 🙏

@joaofnfernandes joaofnfernandes added the area/compose Relates to docker-compose.yml spec or docker-compose binary label Jun 20, 2018
@worp1900
Copy link

I reckon this can be closed as it's fairly well documented here:
https://docs.docker.com/compose/compose-file/#variable-substitution

as referenced in @waltertross documentation:

For more information, see the Variable substitution section in the Compose file reference.

@ghost
Copy link

ghost commented Jan 2, 2019

Closing this ticket due to its age, and the impending refactor. If you think this is in error, feel free to reopen. Thanks!

@JeffreyCA
Copy link

To be exact, it should be:

version: '3.1'

services:
  lb:
    image: nginx:latest
    environment:
      - PASSWORD="${PASS:-secret}"

Note the added dash and an equal sign instead of a colon.

@bendavis78
Copy link

@worp1900:

I reckon this can be closed as it's fairly well documented here:
https://docs.docker.com/compose/compose-file/#variable-substitution

This page no longer has documentation about variable substitution. Is there an updated link?

@agrml
Copy link

agrml commented Jan 22, 2021

There's no info about "docker compose default environment variable value" found by google in the documentation. Only this issue was found. Since it's beyond basic bash knowledges, please place it to the compose file docs.

@kid4git
Copy link

kid4git commented Feb 26, 2021

Docs seem to have been restructured by compose file version. This link works:
https://docs.docker.com/compose/compose-file/compose-file-v3/#variable-substitution

@belegnar
Copy link

x-defaults: &defaults
  environment:
    - VAR=value

services:
  service1:
    <<: *defaults
  service2:
    <<: *defaults

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

/lifecycle locked

@docker docker locked and limited conversation to collaborators Mar 14, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/compose Relates to docker-compose.yml spec or docker-compose binary lifecycle/locked
Projects
None yet
Development

No branches or pull requests

9 participants