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).
Example: The below example demonstrate how to declare default environmental variable for Docker Compose.
$ cat .env
TAG=v1.5
$ cat docker-compose.yml
version: '3'
services:
web:
image: "webapp:${TAG}"
When you run docker-compose up, the web service defined above uses the image webapp:v1.5. You can verify this with the `docker-compose config` command which prints your resolved application config to the terminal.
$ docker-compose config
version: '3'
services:
web:
image: 'webapp:v1.5'