Setting boolean value in docker-compose.yaml using environment variable

Viewed 11718

As docker documentation suggests boolean values in a docker-compose file should be enclosed in single quotes to avoid misinterpretation by the YAML parser. I have docker-compose file that populates some of the values with environment variables of the shell where it gets invoked

myservice:
  environment:
    - firstvar: ${MY_FIRST_VAL}
    - ...
    - booleanvar: ${MY_BOOLEAN_VAL} 

MY_BOOLEAN_VAL can be either true or false and is exposed via a config file. I tried '${MY_BOOLEAN_VAL}' and "${MY_BOOLEAN_VAL}" instead of ${MY_BOOLEAN_VAL} hoping for docker stack deploy to force a bash-like mechanism for neutralising the YAML parser to no avail.

How can I pass a boolean value using an environment variable to compose file?

2 Answers

I believe you've mixed up syntax, try:

environment:
  - booleanvar=${MY_BOOLEAN_VAL}

or

environment:
  booleanvar: ${MY_BOOLEAN_VAL}
environment:
  booleanvar: ${MY_BOOLEAN_VAL}

docker-compose <- v1 not working...

use docker compose v2

docker compose -f docker-compose.yaml down
docker compose -f docker-compose.yaml build
docker compose -f docker-compose.yaml up -d

https://github.com/confluentinc/kafka-images/issues/170

Related