Answering your question ...
One thing I use to do when building a new docker container is understand what the image I pull from does when is builded.
In your docker-compose.yml tou have this
# The Database
database:
image: mysql:5.7
This is the image you pull from, "mysql:5.7"
Dockerhub is a repository where you can find info of this images.
Do a google search "mysql:5.7 dockerhub"
First result is https://hub.docker.com/_/mysql/
There you have your image 5.7, if you click on 5.7 you have this
https://github.com/docker-library/mysql/blob/607b2a65aa76adf495730b9f7e6f28f146a9f95f/5.7/Dockerfile
Which is the Dockerfile from the image, you can have a look at interesting things that happen when building the image.
One of this is ENTRYPOINT ["docker-entrypoint.sh"]
This is the file that got executed when image is ready
I you go one level up in the repo you will see this file
https://github.com/docker-library/mysql/tree/607b2a65aa76adf495730b9f7e6f28f146a9f95f/5.7
The you can see your environment variables being used to create new database etc...
file_env 'MYSQL_DATABASE'
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
mysql+=( "$MYSQL_DATABASE" )
fi