Since your compose file has no varable reference at all, it is not surprising that the .env.dev
is not used. Again, the .env
file or anything you set as a parameter of docker compose
to override the default is only for using variables in the compose file. Not in containers. You have to refer those variables in your compose file. There are examples in the documentation I linked to demonstrate it. It is in fact the first thing on the page I linked in my previous post.
If you PHP app read any of the variables in your .env
file, it is possible the PHP app reads it directly since you mounted the project folder.
So if you want your variables to be available in containers, you have two options.
Option 1: Use the env_file
option in the compose file combined with a variable passed to the compose file:
services:
servicename:
env_file: .env.${MODE}
MODE=dev docker compose up -d
Option 2: refer to individual variables in the compose file under the “environment” section the same way I did in the above example to refer to MODE.
.env.dev
VARNAME=value
services:
servicename:
environment:
VARNAME: ${VARNAME}
docker compose --env-file .env.dev up -d