My Docker Compose expects a boolean (docs):
version: '3.8'
services:
backend:
build:
no_cache: ${NO_CACHE}
I trigger the build like this:
NO_CACHE=true docker compose up
But I get the error
services.backend.build.no_cache must be a boolean
I’ve tried replacing ${NO_CACHE}
with '${NO_CACHE}'
and "${NO_CACHE}"
after reading this SO answer as well as the Docker docs, but I get the same error in both cases. How can I inject a boolean from environment variables into a Docker Compose field?
$ docker -v
Docker version 20.10.17, build 100c701
2
Answers
Set environment variable:
If the issue is that Docker Compose does not natively support injecting boolean values from environment variables (because environment variables are always treated as strings, enclosed in quotes), then you might need a wrapper script (to wrap the
docker compose up
call).For testing, try and write a shell script (
run-docker.sh
+chmod 755 run-docker.sh
) to read the environment variable and then set theno_cache
option in thedocker-compose.yml
file based on the value of that variable.You would then use
docker-compose
to build your services using the now correctly setno_cache
option.This script assumes that your
docker-compose.yml
contains a line that matches the regular expressionno_cache: .*
. You will need to adjust thesed
command if your file is structured differently.Then call it with: