Skip to content

Commit 365d8af

Browse files
committed
add interpolation to docs
1 parent 4021477 commit 365d8af

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/concepts/interpolation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Interpolation
3+
description: Construct environment variable values in `compose.yml` file by referencing other configuration variables.
4+
sidebar_position: 200
5+
---
6+
7+
# Interpolation
8+
9+
Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container.
10+
11+
Variables can be set by assigning a literal value, a reference to a [configuration value](./configuration.md), or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services.
12+
13+
```
14+
service:
15+
environment:
16+
- USER_PASSWORD // configuration variable
17+
- USER_NAME // configuration variable
18+
- CONNECT=dbservice:${USER_NAME}:${USER_PASSWORD}@$example.com:9876
19+
```
20+
In the example, if we assume the value of the configuration variable ***USER_PASSWORD*** is *password* then the value assigned to ***CONNECT*** will be *dbservice:alice:password@example.com:9876*
21+
22+
23+
During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled.

0 commit comments

Comments
 (0)