There is no need for an env file. If you use only the variable name in the docker compose environment definition, its value will automatically be transferred from your host to the container:
services:
db:
image: "mysql:5.7"
ports: ['3306:3306']
environment:
MYSQL_ROOT_PASSWORD:
From the documentation:
Environment variables with only a key are resolved to their
values on the machine Compose is running on, which can be
helpful for secret or host-specific values.
If for some reason, you want or need to use an env file, you also can:
services:
db:
image: "mysql:5.7"
ports: ['3306:3306']
env_file:
- production.env
and in your production.env file (or whatever you name it), just put lines of key=value:
MYSQL_ROOT_PASSWORD=7op-s3cr37
See also The “env_file” configuration option.