Docker.github.io: default values for environment variables?

Created on 20 Jun 2018  路  7Comments  路  Source: docker/docker.github.io

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

areCompose

Most helpful comment

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 馃檹

All 7 comments

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 馃檹

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.

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

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.

@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?

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanJ210 picture DanJ210  路  3Comments

GPPassos picture GPPassos  路  3Comments

thunder1902 picture thunder1902  路  3Comments

mdlinville picture mdlinville  路  3Comments

HariSekhon picture HariSekhon  路  3Comments