.env file placed in the same directory as the
docker-compose.yml is used for variable substitutions in the compose files only.
On the other hand, you can define a
env_file key to pass env vars from a file to the container at runtime:
services: some_service: image: someimg env_file: - .env
It works like the environment statement in a
docker run -e.
As the list type implied you can use multiple files for example to override some generic config key for a specific service.