Compose supports declaring default environment variables in an environment file named .env placed in the project directory. Docker Compose versions earlier than 1.28, load the .env file from the current working directory, where the command is executed, or from the project directory if this is explicitly set with the --project-directory option. This inconsistency has been addressed starting with +v1.28 by limiting the default .env file path to the project directory. You can use the --env-file commandline option to override the default .env and specify the path to a custom environment file.
The project directory is specified by the order of precedence:
--project-directory flag--file flagThe following syntax rules apply to the .env file:
env file to be in VAR=VAL format.# are processed as comments and ignored.The environment variables you define here are used for variable substitution in your Compose file, and can also be used to define the following CLI variables:
COMPOSE_API_VERSIONCOMPOSE_CONVERT_WINDOWS_PATHSCOMPOSE_FILECOMPOSE_HTTP_TIMEOUTCOMPOSE_PROFILESCOMPOSE_PROJECT_NAMECOMPOSE_TLS_VERSIONDOCKER_CERT_PATHDOCKER_HOSTDOCKER_TLS_VERIFYNotes
- Values present in the environment at runtime always override those defined inside the
.envfile. Similarly, values passed via command-line arguments take precedence as well.- Environment variables defined in the
.envfile are not automatically visible inside containers. To set container-applicable environment variables, follow the guidelines in the topic Environment variables in Compose, which describes how to pass shell environment variables through to containers, define environment variables in Compose files, and more.
fig, composition, compose, docker, orchestration, environment, env file
© 2019 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.
https://docs.docker.com/compose/env-file/