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/#multiple-isolated-environments-on-a-single-host
docker compose
is thecompose
sub-command of thedocker
executable (which doesn't exist in this list docs.docker.com/engine/reference/commandline/docker).docker-compose
is a separate executable: docs.docker.com/compose/reference/overview.compose
sub command not listed in the child commands doc. Let's see what the response is.