You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By leveraging environment variables and interpolation in Docker Compose, you can create versatile and reusableconfigurations, 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.
Copy file name to clipboardExpand all lines: content/manuals/compose/how-tos/environment-variables/envvars-precedence.md
+26-21Lines changed: 26 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ aliases:
12
12
13
13
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.
14
14
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.
16
16
17
17
The order of precedence (highest to lowest) is as follows:
18
18
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
59
59
60
60
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.
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.
83
83
@@ -87,7 +87,7 @@ Result 3: The `environment` attribute in the Compose file defines an explicit va
87
87
88
88
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
89
89
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.
91
91
92
92
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.
93
93
@@ -104,3 +104,8 @@ Result 11: The `environment` attribute in the Compose file is set to replicate `
104
104
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.
105
105
106
106
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)
title: Configure pre-defined environment variables in Docker Compose
5
5
linkTitle: Pre-defined environment variables
6
6
weight: 30
7
7
aliases:
8
8
- /compose/reference/envvars/
9
9
- /compose/environment-variables/envvars/
10
10
---
11
11
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.
13
13
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:
15
15
16
16
-`COMPOSE_PROJECT_NAME`
17
17
-`COMPOSE_FILE`
@@ -30,16 +30,19 @@ This page contains information on how you can set or change the following pre-de
30
30
31
31
## Methods to override
32
32
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)
|[`.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. |
37
38
38
39
When changing or setting any environment variables, be aware of [Environment variable precedence](envvars-precedence.md).
39
40
40
-
## Configure
41
+
## Configuration details
41
42
42
-
### COMPOSE\_PROJECT\_NAME
43
+
### Project and file configuration
44
+
45
+
#### COMPOSE\_PROJECT\_NAME
43
46
44
47
Sets the project name. This value is prepended along with the service name to
45
48
the container's name on startup.
@@ -64,7 +67,7 @@ constraint, you must use one of the other mechanisms.
64
67
65
68
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).
66
69
67
-
### COMPOSE\_FILE
70
+
####COMPOSE\_FILE
68
71
69
72
Specifies the path to a Compose file. Specifying multiple Compose files is supported.
70
73
@@ -81,7 +84,7 @@ Specifies the path to a Compose file. Specifying multiple Compose files is suppo
81
84
82
85
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).
83
86
84
-
### COMPOSE\_PROFILES
87
+
####COMPOSE\_PROFILES
85
88
86
89
Specifies one or more profiles to be enabled when `docker compose up` is run.
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).
102
105
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
104
129
105
130
When enabled, Compose performs path conversion from Windows-style to Unix-style in volume definitions.
106
131
@@ -109,15 +134,7 @@ When enabled, Compose performs path conversion from Windows-style to Unix-style
109
134
-`false` or `0`, to disable
110
135
- Defaults to: `0`
111
136
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
121
138
122
139
When enabled, Compose doesn't try to detect orphaned containers for the project.
123
140
@@ -126,7 +143,7 @@ When enabled, Compose doesn't try to detect orphaned containers for the project.
126
143
-`false` or `0`, to disable
127
144
- Defaults to: `0`
128
145
129
-
### COMPOSE\_REMOVE\_ORPHANS
146
+
####COMPOSE\_REMOVE\_ORPHANS
130
147
131
148
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.
132
149
@@ -135,11 +152,13 @@ When enabled, Compose automatically removes orphaned containers when updating a
135
152
-`false` or `0`, to disable automatic removal. Compose displays a warning about orphaned containers instead.
136
153
- Defaults to: `0`
137
154
138
-
### COMPOSE\_PARALLEL\_LIMIT
155
+
####COMPOSE\_PARALLEL\_LIMIT
139
156
140
157
Specifies the maximum level of parallelism for concurrent engine calls.
141
158
142
-
### COMPOSE\_ANSI
159
+
### Output
160
+
161
+
#### COMPOSE\_ANSI
143
162
144
163
Specifies when to print ANSI control characters.
145
164
@@ -149,7 +168,7 @@ Specifies when to print ANSI control characters.
149
168
-`always` or `0`, use TTY mode
150
169
- Defaults to: `auto`
151
170
152
-
### COMPOSE\_STATUS\_STDOUT
171
+
####COMPOSE\_STATUS\_STDOUT
153
172
154
173
When enabled, Compose writes its internal status and progress messages to `stdout` instead of `stderr`.
155
174
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
159
178
-`false` or `0`, to disable
160
179
- Defaults to: `0`
161
180
162
-
### COMPOSE\_ENV\_FILES
181
+
####COMPOSE\_PROGRESS
163
182
164
-
Lets you specify which environment files Compose should use if `--env-file` isn't used.
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.
167
186
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`.
171
189
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
173
191
174
-
### COMPOSE\_MENU
192
+
####COMPOSE\_MENU
175
193
176
194
{{< summary-bar feature_name="Compose menu" >}}
177
195
@@ -182,26 +200,17 @@ When enabled, Compose displays a navigation menu where you can choose to open th
182
200
-`false` or `0`, to disable
183
201
- Defaults to: `1` if you obtained Docker Compose through Docker Desktop, otherwise the default is `0`
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.
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
-
205
214
## Unsupported in Compose V2
206
215
207
216
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
216
225
-`COMPOSE_INTERACTIVE_NO_CLI`
217
226
-`COMPOSE_DOCKER_CLI_BUILD`
218
227
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.
Copy file name to clipboardExpand all lines: content/manuals/compose/how-tos/file-watch.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,10 +207,6 @@ This setup demonstrates how to use the `sync+restart` action in Docker Compose t
207
207
> or [local setup for Docker docs](https://github.com/docker/docs/blob/main/CONTRIBUTING.md)
208
208
> for a demonstration of Compose `watch`.
209
209
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).
0 commit comments