/Docker 17

Declare default environment variables in file

Compose supports declaring default environment variables in an environment file named .env placed in the folder where the docker-compose command is executed (current working directory).

Syntax Rules

These syntax rules apply to the .env file:

  • Compose expects each line in an env file to be in VAR=VAL format.
  • Lines beginning with # (i.e. comments) are ignored.
  • Blank lines are ignored.
  • There is no special handling of quotation marks (i.e. they will be part of the VAL, you have been warned ;) ).

Compose file and CLI variables

The environment variables you define here will be used for variable substitution in your Compose file, and can also be used to define the following CLI variables:



  • Values present in the environment at runtime will always override those defined inside the .env file. Similarly, values passed via command-line arguments take precedence as well.

  • Environment variables defined in the .env file 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.

More Compose documentation

fig, composition, compose, docker, orchestration, environment, env file

© 2017 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.