Why is laravel not connecting to mysql when visited through website, but docker command works?

  docker, laravel, mysql

I am using docker to deploy my laravel app and it does work when I echo "DB_HOST=blabla" and so on into .env file in Dockerfile.

When I docker run with -e="DB_HOST=blabla" etc, and then run a docker exec command on the container with php artisan migrate, it DOES migrate. BUT, when I visit the website, my api routes return error 500 saying: [2002] Connection refused

Can anyone help?

Source: Docker Questions