Configure pre-defined environment variables in Docker Compose
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 for details.
This page explains how to set or change the following pre-defined environment variables:
COMPOSE_PROJECT_NAMECOMPOSE_FILECOMPOSE_PROFILESCOMPOSE_CONVERT_WINDOWS_PATHSCOMPOSE_PATH_SEPARATORCOMPOSE_IGNORE_ORPHANSCOMPOSE_REMOVE_ORPHANSCOMPOSE_PARALLEL_LIMITCOMPOSE_ANSICOMPOSE_STATUS_STDOUTCOMPOSE_ENV_FILESCOMPOSE_DISABLE_ENV_FILECOMPOSE_MENUCOMPOSE_EXPERIMENTALCOMPOSE_PROGRESS
Methods to override
| Method | Description |
|---|---|
.env file | Located in the working directory. |
| Shell | Defined in the host operating system shell. |
| CLI | Passed with --env or -e flag at runtime. |
When changing or setting any environment variables, be aware of Environment variable precedence.
Configuration details
Project and file configuration
COMPOSE_PROJECT_NAME
Sets the project name. This value is prepended along with the service name to the container's name on startup.
For example, if your project name is myapp and it includes two services db and web,
then Compose starts containers named myapp-db-1 and myapp-web-1 respectively.
Compose can set the project name in different ways. The level of precedence (from highest to lowest) for each method is as follows:
- The
-pcommand line flag COMPOSE_PROJECT_NAME- The top-level
name:variable from the config file (or the lastname:from a series of config files specified using-f) - The
basenameof the project directory containing the config file (or containing the first config file specified using-f) - The
basenameof the current directory if no config file is specified
Project names must contain only lowercase letters, decimal digits, dashes, and
underscores, and must begin with a lowercase letter or decimal digit. If the
basename of the project directory or current directory violates this
constraint, you must use one of the other mechanisms.
See also the
command-line options overview and
using -p to specify a project name.
COMPOSE_FILE
Specifies the path to a Compose file. Specifying multiple Compose files is supported.
- Default behavior: If not provided, Compose looks for a file named
compose.yamlin the current directory and, if not found, then Compose searches each parent directory recursively until a file by that name is found. - When specifying multiple Compose files, the path separators are, by default, on:
Mac and Linux:
:(colon)Windows:
;(semicolon) For example:COMPOSE_FILE=compose.yaml:compose.prod.yaml
COMPOSE_PATH_SEPARATOR.
See also the
command-line options overview and
using -f to specify name and path of one or more Compose files.
COMPOSE_PROFILES
Specifies one or more profiles to be enabled when docker compose up is run.
Services with matching profiles are started as well as any services for which no profile has been defined.
For example, calling docker compose up with COMPOSE_PROFILES=frontend selects services with the
frontend profile as well as any services without a profile specified.
If specifying multiple profiles, use a comma as a separator.
The following example enables all services matching both the frontend and debug profiles and services without a profile.
COMPOSE_PROFILES=frontend,debug
See also Using profiles with Compose and the
--profile command-line option.
COMPOSE_PATH_SEPARATOR
Specifies a different path separator for items listed in COMPOSE_FILE.
- Defaults to:
- On macOS and Linux to
: - On Windows to
;
- On macOS and Linux to
COMPOSE_ENV_FILES
Specifies 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:
COMPOSE_ENV_FILES=.env.envfile1,.env.envfile2
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.
COMPOSE_DISABLE_ENV_FILE
Lets you disable the use of the default .env file.
- Supported values:
trueor1, Compose ignores the.envfilefalseor0, Compose looks for an.envfile in the project directory
- Defaults to:
0
Environment handling and container lifecycle
COMPOSE_CONVERT_WINDOWS_PATHS
When enabled, Compose performs path conversion from Windows-style to Unix-style in volume definitions.
- Supported values:
trueor1, to enablefalseor0, to disable
- Defaults to:
0
COMPOSE_IGNORE_ORPHANS
When enabled, Compose doesn't try to detect orphaned containers for the project.
- Supported values:
trueor1, to enablefalseor0, to disable
- Defaults to:
0
COMPOSE_REMOVE_ORPHANS
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.
- Supported values:
trueor1, to enable automatic removal of orphaned containersfalseor0, to disable automatic removal. Compose displays a warning about orphaned containers instead.
- Defaults to:
0
COMPOSE_PARALLEL_LIMIT
Specifies the maximum level of parallelism for concurrent engine calls.
Output
COMPOSE_ANSI
Specifies when to print ANSI control characters.
- Supported values:
auto, Compose detects if TTY mode can be used. Otherwise, use plain text modenever, use plain text modealwaysor0, use TTY mode
- Defaults to:
auto
COMPOSE_STATUS_STDOUT
When enabled, Compose writes its internal status and progress messages to stdout instead of stderr.
The default value is false to clearly separate the output streams between Compose messages and your container's logs.
- Supported values:
trueor1, to enablefalseor0, to disable
- Defaults to:
0
COMPOSE_PROGRESS
Defines the type of progress output, if --progress isn't used.
Supported values are auto, tty, plain, json, and quiet.
Default is auto.
User experience
COMPOSE_MENU
When enabled, Compose displays a navigation menu where you can choose to open the Compose stack in Docker Desktop, switch on watch mode, or use
Docker Debug.
- Supported values:
trueor1, to enablefalseor0, to disable
- Defaults to:
1if you obtained Docker Compose through Docker Desktop, otherwise the default is0
COMPOSE_EXPERIMENTAL
This is an opt-out variable. When turned off it deactivates the experimental features.
- Supported values:
trueor1, to enablefalseor0, to disable
- Defaults to:
1
Unsupported in Compose V2
The following environment variables have no effect in Compose V2. For more information, see Migrate to Compose V2.
COMPOSE_API_VERSIONBy default the API version is negotiated with the server. UseDOCKER_API_VERSION.
See the Docker CLI environment variable reference page.COMPOSE_HTTP_TIMEOUTCOMPOSE_TLS_VERSIONCOMPOSE_FORCE_WINDOWS_HOSTCOMPOSE_INTERACTIVE_NO_CLICOMPOSE_DOCKER_CLI_BUILDUseDOCKER_BUILDKITto select between BuildKit and the classic builder. IfDOCKER_BUILDKIT=0thendocker compose builduses the classic builder to build images.