In addition to what has been already said here, I have noticed an important difference between the two.
In our setup, the docker-compose.yml file is located in a template folder. This way we can run multiple instances of the same project based on the same template. The local instance has its own folder with its own .env file (and also its own volumes).
There is also a template .env file in the template folder : copied and adapted to the instance folder using a script.
In order to work, the docker-compose.yml file looks like this, in the template folder :
version: "3"
services:
wordpress:
image: wordpress
container_name: "${COMPOSE_PROJECT_NAME}_wordpress"
env_file:
- ${PWD}/.env
...
And the local instance .env file :
# compose file location
COMPOSE_FILE=../templateFolder/docker-compose.yml
# this instance name
COMPOSE_PROJECT_NAME=foo
In this context :
- with
docker-compose, the .env file is read in the instance location, which is expected
- with
docker compose, the .env file is read in the template location !
To override this, we had to rename the template .env file into dotEnv.
This behavior is very lightly described here : https://docs.docker.com/compose/features-uses/#have-multiple-isolated-environments-on-a-single-host.
For posterity, the light description is:
Compose uses a project name to isolate environments from each other. ...
The default project name is the basename of the project directory. ...
The default project directory is the base directory of the Compose file. A custom value for it can be defined with the --project-directory command line option.
docker composeis thecomposesub-command of thedockerexecutable (which doesn't exist in this list docs.docker.com/engine/reference/commandline/docker).docker-composeis a separate executable: docs.docker.com/compose/reference/overview.composesub command not listed in the child commands doc. Let's see what the response is.