Laravel with Docker: wrong DB selected when testing

My docker containers are as such:

  • worklog_laravel_app (Laravel app)
  • worklog_laravel_web (Nginx)
  • worklog_laravel_db (MySQL)

I have two databases setup in the worklog_laravel_db container:

  • worklog
  • worklog_test

Right now, I’m in the midst of writing tests for my app via docker exec -it bash on the worklog_laravel_app container.

I’ve already setup my env.testing to have the same vars as .env, except:

  • APP_ENV=testing
  • DB_DATABASE=worklog_test

But running tests still ends up selecting the local dev DB (worklog) instead.

Why is this so? And how do I resolve this?

Source: StackOverflow