0

I have Laradock setup and serving a website in larval, but when I try to run php artisan migrate I get this error.

 SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from  information_schema.tables where table_schema = yt and table_name = migrations)



DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=yt
DB_USERNAME=root
DB_PASSWORD=root

I can not seem to find a solution to my issue.

John Freedom
  • 471
  • 4
  • 6
  • 11

2 Answers2

0

First thing you should check which container run the mysql service :

sudo docker ps

Maybe it not expose the port from mysql container to localhost (127.0.0.1) so laravel can't connect to it . Find the mysql container name then change the DB_HOST .Let take an example:

app-container 172.0.0.1 mysql-container 172.0.0.2

Because when docker run up ,it will create a virtual networking for itself ,then it will expose to your computer .So if you want laravel can work with msql ,you should change the DB_HOST to 172.0.0.2 in this example case .

0

I had same issue with Laradock on MacOS, couldn't connect to MariaDB container.

My way:

  1. Get correct name for MariaDB container:

docker ps

  1. Inspect container (for example container name is: container_mariadb_1)

docker inspect container_mariadb_1

  1. At very bottom of long list of parameters you can see IPAddress

"IPAddress": "172.26.0.3"

I put this IP in Laravel's .env config file as DB_HOST and this is it. Of course I'm not sure if this way is really correct, but I know that it's work for me at least twice.

UPDATE: Also in my case Laravel connects to MariaDB normally if I use DB_HOST=mariadb in .env file.

GiN
  • 392
  • 1
  • 3
  • 12