I’m currently using container environment variables (exported by my docker-entrypoint.sh
) to configure Visual Studio Code settings and it works perfectly with string
values:
{
"intelephense.environment.phpVersion": "${containerEnv:PHP_VERSION}",
}
However, when the values must be of type number
or boolean
, an issue arises (DB_ASK_PASSWORD
contains either true
or false
). In fact, I’m forced to wrap the value into double quotes, producing an invalid number
or boolean
:
{
"sqltools.connections": [
{
"port": "${containerEnv:DB_HOST}",
"askForPassword": "${containerEnv:DB_ASK_PASSWORD}"
}
]
}
Even if, in this specific case, port
could work (for internal type conversion), askForPassword
cannot. Being wrapped by double quotes, the "false"
text is interpreted as as truthy value.
Is there any way to accomplish what I’m asking? Removing the quotes does not help either:
{
"sqltools.connections": [
{
"askForPassword": ${containerEnv:DB_ASK_PASSWORD}
}
]
}
2
Answers
Settings do not support variables automatically, the extension using the setting has to implement variables.
Most likely
intelephense
does support the${containerEnv}
variable andsqltools
does not.You can create a file called devcontainer.env in your .devcontainer folder, and put your variables there:
Then, in your devcontainer.json file, you can add this line:
To learn more about this, see https://code.visualstudio.com/remote/advancedcontainers/environment-variables
I hope this helps you configure your Visual Studio Code settings.