Compose: Variable substitution issue with curly braces in default values

Created on 6 Dec 2016  路  4Comments  路  Source: docker/compose

Variable substitution doesn't seem to work correctly when there is a default value which itself contains curly braces. I saw the documentation stating that $$ can be used to escape $ but didn't see anything about escaping curly braces (doubling them up didn't seem to help). Steps to reproduce:

Create a docker-compose.yml with the following contents:

````
version: '2.1'

services:

hello-world:
image: hello-world:latest
environment:
- URL_TEMPLATE=${URL_TEMPLATE:-http://example.org/{urlTemplateVariable}/some-sub-directory}
````

docker-compose up then examine the environment variables of the container (e.g. docker inspect -f "{{ .Config.Env }}" test_hello-world_1).

Expected value of URL_TEMPLATE:
http://example.org/{urlTemplateVariable}/some-sub-directory

Actual value is:
http://example.org/{urlTemplateVariable/some-sub-directory}

This also seems to cause problems when trying to override the default value from a .env file. If you add a .env like so:

URL_TEMPLATE=http://example.net

The expected value of URL_TEMPLATE is:
http://example.net

Actual value is:
http://example.net/some-sub-directory}

areconfig kinenhancement stale

All 4 comments

There's currently no way to escape curly braces inside a variable declaration. The evaluation will stop at the first closing brace.

Just ran into this issue trying to set a default value for a variable which is supposed to be a JSON object which I'm setting as the value for an arg

args:
  FIREBASE_CONFIG: '${FIREBASE_CONFIG-''{ "projectId": "my-fbProj" }''}'

being able to backslash escape the closing brace would be really helpful, the best I can do now is error if it isn't defined in an environment variable, .env file or commandline option.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it had not recent activity during the stale period.

Was this page helpful?
0 / 5 - 0 ratings