Answer the question
In order to leave comments, you need to log in
Why can't I connect to the database in laravel on laradock?
Can't connect to database from docker container in Laravel.
Project structure
What I do in sequence:
1. From the laradock directory I run $ docker-compose up -d nginx mysql
2. I go into the container $ docker-compose exec workspace bash
3. I try to make the first migration php artisan migrate
And I get an error SQLSTATE[HY000] [ 2002] Connection refused (SQL: select * from information_schema.tables where table_schema = project and table_name = migrations and table_type = 'BASE TABLE')
Laravel config:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33061
DB_DATABASE=project
DB_USERNAME=project
DB_PASSWORD=secret
MYSQL_VERSION=5.7
MYSQL_DATABASE=project
MYSQL_USER=project
MYSQL_PASSWORD=secret
MYSQL_PORT=33061
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '33061'),
'database' => env('DB_DATABASE', 'project'),
'username' => env('DB_USERNAME', 'project'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question