Support the ongoing development of Laravel.io →
posted 2 months ago
Sail Artisan
Last updated by @zanoth 3 weeks ago.
0

First off, peep into the .env file in Laravel. Double-check if the DB_HOST matches the service in your docker-compose.yaml. Seems like yours is mysql.

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=yourdbname
DB_USERNAME=youruser
DB_PASSWORD=yourpassword

Also, take a quick look at config/database.php in Laravel. If you're not using MySQL socket, ditch the unix_socket line.

'mysql' => [
   'driver' => 'mysql',
   'host' => env('DB_HOST', '127.0.0.1'),
   'port' => env('DB_PORT', '3306'),
   'database' => env('DB_DATABASE', 'forge'),
   'username' => env('DB_USERNAME', 'forge'),
   'password' => env('DB_PASSWORD', ''),
   'unix_socket' => env('DB_SOCKET', ''), // Drop this line if unnecessary
   // ...
],

Check the volumes in your docker-compose.yaml, and make sure the MySQL image (mysql/mysql-server:8.0) is all good.

After those tweaks, give running migrations another shot with Laravel Sail:

sail artisan migrate

If the struggle persists, peek into Laravel logs (storage/logs) for more details. And make sure MySQL is up and running smooth inside that Docker container. Good luck, mate!

zanoth liked this reply

1
moderator

Hello @zanoth

Did you read the documentation for Sail? (Especially about the database) https://laravel.com/docs/10.x/sail#mysql

The error gives me the idea that you didn't set/change the DB_HOST variable in your .env file to mysql is that correct?

zanoth liked this reply

1

Thanks guys, It has been solved. Seemly a simple networks: - sail which was missing on docker-compose.yaml. :)

lucasdonordeste, tvbeek liked this reply

2
Solution selected by @driesvints

Sign in to participate in this thread!

Eventy

Your banner here too?

ivan zanoth Joined 19 Feb 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.