Skip to content

Commit 021536b

Browse files
authored
Enhance examples in reference/compose-file/configs (#23185)
## Description Reworked docker-compose configs examples slightly
1 parent 89344f4 commit 021536b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

content/reference/compose-file/configs.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ By default, the config:
1616
- Is owned by the user running the container command but can be overridden by service configuration.
1717
- Has world-readable permissions (mode 0444), unless the service is configured to override this.
1818

19-
The top-level `configs` declaration defines or references configuration data that is granted to services in your Compose application. The source of the config is either `file` or `external`.
19+
The top-level `configs` declaration defines or references configuration data that is granted to services in your Compose application. The source of the config is either `file`, `environment`, `content`, or `external`.
2020

2121
- `file`: The config is created with the contents of the file at the specified path.
2222
- `environment`: The config content is created with the value of an environment variable. Introduced in Docker Compose version [2.23.1](/manuals/compose/releases/release-notes.md#2231).
@@ -48,6 +48,21 @@ configs:
4848

4949
## Example 2
5050

51+
External configs lookup can also use a distinct key by specifying a `name`.
52+
53+
The following
54+
example modifies the previous one to look up a config using the parameter `HTTP_CONFIG_KEY`. The actual lookup key is set at deployment time by the [interpolation](interpolation.md) of
55+
variables, but exposed to containers as hard-coded ID `http_config`.
56+
57+
```yml
58+
configs:
59+
http_config:
60+
external: true
61+
name: "${HTTP_CONFIG_KEY}"
62+
```
63+
64+
## Example 3
65+
5166
`<project_name>_app_config` is created when the application is deployed,
5267
by registering the inlined content as the configuration data. This means Compose infers variables when creating the config, which allows you to
5368
adjust content according to service configuration:
@@ -61,19 +76,15 @@ configs:
6176
spring.application.name=${COMPOSE_PROJECT_NAME}
6277
```
6378

64-
## Example 3
79+
## Example 4
6580

66-
External configs lookup can also use a distinct key by specifying a `name`.
67-
68-
The following
69-
example modifies the previous one to look up a config using the parameter `HTTP_CONFIG_KEY`. The actual lookup key is set at deployment time by the [interpolation](interpolation.md) of
70-
variables, but exposed to containers as hard-coded ID `http_config`.
81+
`<project_name>_simple_config` is created when the application is deployed,
82+
using the value of an environment variable as the configuration data. This is useful for simple configuration values that don’t require interpolation:
7183

7284
```yml
7385
configs:
74-
http_config:
75-
external: true
76-
name: "${HTTP_CONFIG_KEY}"
86+
simple_config:
87+
environment: "SIMPLE_CONFIG_VALUE"
7788
```
7889

7990
If `external` is set to `true`, all other attributes apart from `name` are irrelevant. If Compose detects any other attribute, it rejects the Compose file as invalid.

0 commit comments

Comments
 (0)