The documentation explains how you cans et variables and which parameter in the compsoe file is for what.
env_file and environment are alternatives for the same thing. To set a variable in a container, not to use in the compose file. That would require interpreting the yaml, reading the referred file and interpreting the yaml again
You need either the default .env file or overriding it from the command line with docker compose --env-file And here is one of my comments with a short example