Skip to content

Commit b786ac3

Browse files
authored
Compose freshness for further how-to pages (#22980)
<!--Delete sections as needed --> ## Description Freshness to: - Env variables and closes #22730 - Build dependent images - Secrets - watch ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review
1 parent 91c81cd commit b786ac3

File tree

7 files changed

+109
-79
lines changed

7 files changed

+109
-79
lines changed

content/manuals/compose/how-tos/dependent-images.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ weight: 50
88
{{< summary-bar feature_name="Compose dependent images" >}}
99

1010
To reduce push/pull time and image weight, a common practice for Compose applications is to have services
11-
share base layers as much as possible. You will typically select the same operating system base image for
11+
share base layers as much as possible. You typically select the same operating system base image for
1212
all services. But you can also get one step further by sharing image layers when your images share the same
1313
system packages. The challenge to address is then to avoid repeating the exact same Dockerfile instruction
1414
in all services.
@@ -162,3 +162,8 @@ Bake can also be selected as the default builder by editing your `$HOME/.docker/
162162
...
163163
}
164164
```
165+
166+
## Additional resources
167+
168+
- [Docker Compose build reference](/reference/cli/docker/compose/build.md)
169+
- [Learn about multi-stage Dockerfiles](/manuals/build/building/multi-stage.md)

content/manuals/compose/how-tos/environment-variables/_index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
title: Environment variables in Compose
33
linkTitle: Use environment variables
44
weight: 40
5-
description: Explainer on the ways to set, use and manage environment variables in
6-
Compose
5+
description: Explains how to set, use, and manage environment variables in Docker Compose.
76
keywords: compose, orchestration, environment, env file
87
aliases:
98
- /compose/environment-variables/
109
---
1110

12-
By leveraging environment variables and interpolation in Docker Compose, you can create versatile and reusable configurations, making your Dockerized applications easier to manage and deploy across different environments.
11+
Environment variables and interpolation in Docker Compose help you create reusable, flexible configurations. This makes Dockerized applications easier to manage and deploy across environments.
1312

1413
> [!TIP]
1514
>

content/manuals/compose/how-tos/environment-variables/envvars-precedence.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ aliases:
1212

1313
When the same environment variable is set in multiple sources, Docker Compose follows a precedence rule to determine the value for that variable in your container's environment.
1414

15-
This page contains information on the level of precedence each method of setting environmental variables takes.
15+
This page explains how Docker Compose determines the final value of an environment variable when it's defined in multiple locations.
1616

1717
The order of precedence (highest to lowest) is as follows:
1818
1. Set using [`docker compose run -e` in the CLI](set-environment-variables.md#set-environment-variables-with-docker-compose-run---env).
@@ -59,25 +59,25 @@ The columns `Host OS environment` and `.env` file is listed only for illustratio
5959

6060
Each row represents a combination of contexts where `VALUE` is set, substituted, or both. The **Result** column indicates the final value for `VALUE` in each scenario.
6161

62-
| # | `docker compose run` | `environment` attribute | `env_file` attribute | Image `ENV` | `Host OS` environment | `.env` file | | Result |
63-
|:--:|:----------------:|:-------------------------------:|:----------------------:|:------------:|:-----------------------:|:-----------------:|:---:|:----------:|
64-
| 1 | - | - | - | - | `VALUE=1.4` | `VALUE=1.3` || - |
65-
| 2 | - | - | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | - ||**`VALUE=1.6`** |
66-
| 3 | - | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | - ||**`VALUE=1.7`** |
67-
| 4 | - | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.5`** |
68-
| 5 |`--env VALUE=1.8` | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.8`** |
69-
| 6 |`--env VALUE` | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.4`** |
70-
| 7 |`--env VALUE` | - | - | `VALUE=1.5` | - | `VALUE=1.3` ||**`VALUE=1.3`** |
71-
| 8 | - | - | `VALUE` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.4`** |
72-
| 9 | - | - | `VALUE` | `VALUE=1.5` | - | `VALUE=1.3` ||**`VALUE=1.3`** |
73-
| 10 | - | `VALUE` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.4`** |
74-
| 11 | - | `VALUE` | - | `VALUE=1.5` | - | `VALUE=1.3` ||**`VALUE=1.3`** |
75-
| 12 |`--env VALUE` | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.4`** |
76-
| 13 |`--env VALUE=1.8` | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.8`** |
77-
| 14 |`--env VALUE=1.8` | - | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.8`** |
78-
| 15 |`--env VALUE=1.8` | `VALUE=1.7` | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` ||**`VALUE=1.8`** |
79-
80-
### Result explanation
62+
| # | `docker compose run` | `environment` attribute | `env_file` attribute | Image `ENV` | `Host OS` environment | `.env` file | Result |
63+
|:--:|:----------------:|:-------------------------------:|:----------------------:|:------------:|:-----------------------:|:-----------------:|:----------:|
64+
| 1 | - | - | - | - | `VALUE=1.4` | `VALUE=1.3` | - |
65+
| 2 | - | - | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | - |**`VALUE=1.6`** |
66+
| 3 | - | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | - |**`VALUE=1.7`** |
67+
| 4 | - | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.5`** |
68+
| 5 |`--env VALUE=1.8` | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.8`** |
69+
| 6 |`--env VALUE` | - | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.4`** |
70+
| 7 |`--env VALUE` | - | - | `VALUE=1.5` | - | `VALUE=1.3` |**`VALUE=1.3`** |
71+
| 8 | - | - | `VALUE` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.4`** |
72+
| 9 | - | - | `VALUE` | `VALUE=1.5` | - | `VALUE=1.3` |**`VALUE=1.3`** |
73+
| 10 | - | `VALUE` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.4`** |
74+
| 11 | - | `VALUE` | - | `VALUE=1.5` | - | `VALUE=1.3` |**`VALUE=1.3`** |
75+
| 12 |`--env VALUE` | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.4`** |
76+
| 13 |`--env VALUE=1.8` | `VALUE=1.7` | - | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.8`** |
77+
| 14 |`--env VALUE=1.8` | - | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.8`** |
78+
| 15 |`--env VALUE=1.8` | `VALUE=1.7` | `VALUE=1.6` | `VALUE=1.5` | `VALUE=1.4` | `VALUE=1.3` |**`VALUE=1.8`** |
79+
80+
### Understanding precedence results
8181

8282
Result 1: The local environment takes precedence, but the Compose file is not set to replicate this inside the container, so no such variable is set.
8383

@@ -87,7 +87,7 @@ Result 3: The `environment` attribute in the Compose file defines an explicit va
8787

8888
Result 4: The image's `ENV` directive declares the variable `VALUE`, and since the Compose file is not set to override this value, this variable is defined by image
8989

90-
Result 5: The `docker compose run` command has the `--env` flag set which an explicit value, and overrides the value set by the image.
90+
Result 5: The `docker compose run` command has the `--env` flag set with an explicit value, and overrides the value set by the image.
9191

9292
Result 6: The `docker compose run` command has the `--env` flag set to replicate the value from the environment. Host OS value takes precedence and is replicated into the container's environment.
9393

@@ -104,3 +104,8 @@ Result 11: The `environment` attribute in the Compose file is set to replicate `
104104
Result 12: The `--env` flag has higher precedence than the `environment` and `env_file` attributes and is to set to replicate `VALUE` from the local environment. Host OS value takes precedence and is replicated into the container's environment.
105105

106106
Results 13 to 15: The `--env` flag has higher precedence than the `environment` and `env_file` attributes and so sets the value.
107+
108+
## Next steps
109+
110+
- [Set environment variables in Compose](set-environment-variables.md)
111+
- [Use variable interpolation in Compose files](variable-interpolation.md)

content/manuals/compose/how-tos/environment-variables/envvars.md

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
description: Compose pre-defined environment variables
3-
keywords: fig, composition, compose, docker, orchestration, cli, reference
4-
title: Set or change pre-defined environment variables in Docker Compose
3+
keywords: fig, composition, compose, docker, orchestration, cli, reference, compose environment configuration, docker env variables
4+
title: Configure pre-defined environment variables in Docker Compose
55
linkTitle: Pre-defined environment variables
66
weight: 30
77
aliases:
88
- /compose/reference/envvars/
99
- /compose/environment-variables/envvars/
1010
---
1111

12-
Compose already comes with pre-defined environment variables. It also inherits common Docker CLI environment variables, such as `DOCKER_HOST` and `DOCKER_CONTEXT`. See [Docker CLI environment variable reference](/reference/cli/docker/#environment-variables) for details.
12+
Docker Compose includes several pre-defined environment variables. It also inherits common Docker CLI environment variables, such as `DOCKER_HOST` and `DOCKER_CONTEXT`. See [Docker CLI environment variable reference](/reference/cli/docker/#environment-variables) for details.
1313

14-
This page contains information on how you can set or change the following pre-defined environment variables if you need to:
14+
This page explains how to set or change the following pre-defined environment variables:
1515

1616
- `COMPOSE_PROJECT_NAME`
1717
- `COMPOSE_FILE`
@@ -30,16 +30,19 @@ This page contains information on how you can set or change the following pre-de
3030

3131
## Methods to override
3232

33-
You can set or change the pre-defined environment variables:
34-
- With an [`.env` file located in your working directory](/manuals/compose/how-tos/environment-variables/variable-interpolation.md)
35-
- From the command line
36-
- From your [shell](variable-interpolation.md#substitute-from-the-shell)
33+
| Method | Description |
34+
| ----------- | -------------------------------------------- |
35+
| [`.env` file](/manuals/compose/how-tos/environment-variables/variable-interpolation.md) | Located in the working directory. |
36+
| [Shell](variable-interpolation.md#substitute-from-the-shell) | Defined in the host operating system shell. |
37+
| CLI | Passed with `--env` or `-e` flag at runtime. |
3738

3839
When changing or setting any environment variables, be aware of [Environment variable precedence](envvars-precedence.md).
3940

40-
## Configure
41+
## Configuration details
4142

42-
### COMPOSE\_PROJECT\_NAME
43+
### Project and file configuration
44+
45+
#### COMPOSE\_PROJECT\_NAME
4346

4447
Sets the project name. This value is prepended along with the service name to
4548
the container's name on startup.
@@ -64,7 +67,7 @@ constraint, you must use one of the other mechanisms.
6467

6568
See also the [command-line options overview](/reference/cli/docker/compose/_index.md#command-options-overview-and-help) and [using `-p` to specify a project name](/reference/cli/docker/compose/_index.md#use--p-to-specify-a-project-name).
6669

67-
### COMPOSE\_FILE
70+
#### COMPOSE\_FILE
6871

6972
Specifies the path to a Compose file. Specifying multiple Compose files is supported.
7073

@@ -81,7 +84,7 @@ Specifies the path to a Compose file. Specifying multiple Compose files is suppo
8184

8285
See also the [command-line options overview](/reference/cli/docker/compose/_index.md#command-options-overview-and-help) and [using `-f` to specify name and path of one or more Compose files](/reference/cli/docker/compose/_index.md#use--f-to-specify-the-name-and-path-of-one-or-more-compose-files).
8386

84-
### COMPOSE\_PROFILES
87+
#### COMPOSE\_PROFILES
8588

8689
Specifies one or more profiles to be enabled when `docker compose up` is run.
8790

@@ -100,7 +103,29 @@ COMPOSE_PROFILES=frontend,debug
100103

101104
See also [Using profiles with Compose](../profiles.md) and the [`--profile` command-line option](/reference/cli/docker/compose/_index.md#use-profiles-to-enable-optional-services).
102105

103-
### COMPOSE\_CONVERT\_WINDOWS\_PATHS
106+
#### COMPOSE\_PATH\_SEPARATOR
107+
108+
Specifies a different path separator for items listed in `COMPOSE_FILE`.
109+
110+
- Defaults to:
111+
- On macOS and Linux to `:`
112+
- On Windows to`;`
113+
114+
#### COMPOSE\_ENV\_FILES
115+
116+
Specifies which environment files Compose should use if `--env-file` isn't used.
117+
118+
When using multiple environment files, use a comma as a separator. For example:
119+
120+
```console
121+
COMPOSE_ENV_FILES=.env.envfile1, .env.envfile2
122+
```
123+
124+
If `COMPOSE_ENV_FILES` is not set, and you don't provide `--env-file` in the CLI, Docker Compose uses the default behavior, which is to look for an `.env` file in the project directory.
125+
126+
### Environment handling and container lifecycle
127+
128+
#### COMPOSE\_CONVERT\_WINDOWS\_PATHS
104129

105130
When enabled, Compose performs path conversion from Windows-style to Unix-style in volume definitions.
106131

@@ -109,15 +134,7 @@ When enabled, Compose performs path conversion from Windows-style to Unix-style
109134
- `false` or `0`, to disable
110135
- Defaults to: `0`
111136

112-
### COMPOSE\_PATH\_SEPARATOR
113-
114-
Specifies a different path separator for items listed in `COMPOSE_FILE`.
115-
116-
- Defaults to:
117-
- On macOS and Linux to `:`
118-
- On Windows to`;`
119-
120-
### COMPOSE\_IGNORE\_ORPHANS
137+
#### COMPOSE\_IGNORE\_ORPHANS
121138

122139
When enabled, Compose doesn't try to detect orphaned containers for the project.
123140

@@ -126,7 +143,7 @@ When enabled, Compose doesn't try to detect orphaned containers for the project.
126143
- `false` or `0`, to disable
127144
- Defaults to: `0`
128145

129-
### COMPOSE\_REMOVE\_ORPHANS
146+
#### COMPOSE\_REMOVE\_ORPHANS
130147

131148
When enabled, Compose automatically removes orphaned containers when updating a service or stack. Orphaned containers are those that were created by a previous configuration but are no longer defined in the current `compose.yaml` file.
132149

@@ -135,11 +152,13 @@ When enabled, Compose automatically removes orphaned containers when updating a
135152
- `false` or `0`, to disable automatic removal. Compose displays a warning about orphaned containers instead.
136153
- Defaults to: `0`
137154

138-
### COMPOSE\_PARALLEL\_LIMIT
155+
#### COMPOSE\_PARALLEL\_LIMIT
139156

140157
Specifies the maximum level of parallelism for concurrent engine calls.
141158

142-
### COMPOSE\_ANSI
159+
### Output
160+
161+
#### COMPOSE\_ANSI
143162

144163
Specifies when to print ANSI control characters.
145164

@@ -149,7 +168,7 @@ Specifies when to print ANSI control characters.
149168
- `always` or `0`, use TTY mode
150169
- Defaults to: `auto`
151170

152-
### COMPOSE\_STATUS\_STDOUT
171+
#### COMPOSE\_STATUS\_STDOUT
153172

154173
When enabled, Compose writes its internal status and progress messages to `stdout` instead of `stderr`.
155174
The default value is false to clearly separate the output streams between Compose messages and your container's logs.
@@ -159,19 +178,18 @@ The default value is false to clearly separate the output streams between Compos
159178
- `false` or `0`, to disable
160179
- Defaults to: `0`
161180

162-
### COMPOSE\_ENV\_FILES
181+
#### COMPOSE\_PROGRESS
163182

164-
Lets you specify which environment files Compose should use if `--env-file` isn't used.
183+
{{< summary-bar feature_name="Compose progress" >}}
165184

166-
When using multiple environment files, use a comma as a separator. For example:
185+
Defines the type of progress output, if `--progress` isn't used.
167186

168-
```console
169-
COMPOSE_ENV_FILES=.env.envfile1, .env.envfile2
170-
```
187+
Supported values are `auto`, `tty`, `plain`, `json`, and `quiet`.
188+
Default is `auto`.
171189

172-
If `COMPOSE_ENV_FILES` is not set, and you don't provide `--env-file` in the CLI, Docker Compose uses the default behavior, which is to look for an `.env` file in the project directory.
190+
### User experience
173191

174-
### COMPOSE\_MENU
192+
#### COMPOSE\_MENU
175193

176194
{{< summary-bar feature_name="Compose menu" >}}
177195

@@ -182,26 +200,17 @@ When enabled, Compose displays a navigation menu where you can choose to open th
182200
- `false` or `0`, to disable
183201
- Defaults to: `1` if you obtained Docker Compose through Docker Desktop, otherwise the default is `0`
184202

185-
### COMPOSE\_EXPERIMENTAL
203+
#### COMPOSE\_EXPERIMENTAL
186204

187205
{{< summary-bar feature_name="Compose experimental" >}}
188206

189-
This is an opt-out variable. When turned off it deactivates the experimental features such as the navigation menu or [Synchronized file shares](/manuals/desktop/features/synchronized-file-sharing.md).
207+
This is an opt-out variable. When turned off it deactivates the experimental features.
190208

191209
- Supported values:
192210
- `true` or `1`, to enable
193211
- `false` or `0`, to disable
194212
- Defaults to: `1`
195213

196-
### COMPOSE\_PROGRESS
197-
198-
{{< summary-bar feature_name="Compose progress" >}}
199-
200-
Defines the type of progress output, if `--progress` isn't used.
201-
202-
Supported values are `auto`, `tty`, `plain`, `json`, and `quiet`.
203-
Default is `auto`.
204-
205214
## Unsupported in Compose V2
206215

207216
The following environment variables have no effect in Compose V2.
@@ -216,3 +225,4 @@ For more information, see [Migrate to Compose V2](/manuals/compose/releases/migr
216225
- `COMPOSE_INTERACTIVE_NO_CLI`
217226
- `COMPOSE_DOCKER_CLI_BUILD`
218227
Use `DOCKER_BUILDKIT` to select between BuildKit and the classic builder. If `DOCKER_BUILDKIT=0` then `docker compose build` uses the classic builder to build images.
228+

content/manuals/compose/how-tos/environment-variables/variable-interpolation.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ The following syntax rules apply to environment files:
149149
- `VAR="some\tvalue"` -> `some value`
150150
- `VAR='some\tvalue'` -> `some\tvalue`
151151
- `VAR=some\tvalue` -> `some\tvalue`
152+
- Single-quoted values can span multiple lines. Example:
153+
154+
```yaml
155+
KEY='SOME
156+
VALUE'
157+
```
158+
159+
If you then run `docker compose config`, you'll see:
160+
161+
```yaml
162+
environment:
163+
KEY: |-
164+
SOME
165+
VALUE
166+
```
152167

153168
### Substitute with `--env-file`
154169

content/manuals/compose/how-tos/file-watch.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ This setup demonstrates how to use the `sync+restart` action in Docker Compose t
207207
> or [local setup for Docker docs](https://github.com/docker/docs/blob/main/CONTRIBUTING.md)
208208
> for a demonstration of Compose `watch`.
209209

210-
## Feedback
211-
212-
We are actively looking for feedback on this feature. Give feedback or report any bugs you may find in the [Compose Specification repository](https://github.com/compose-spec/compose-spec/pull/253).
213-
214210
## Reference
215211

216212
- [Compose Develop Specification](/reference/compose-file/develop.md)

0 commit comments

Comments
 (0)