A
A
Albert19912020-07-10 19:12:04
Docker
Albert1991, 2020-07-10 19:12:04

Why can't I connect to the database in laravel on laradock?

Can't connect to database from docker container in Laravel.

Project structure 5f08927111656973288260.png

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


Config from laradock:
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


Just in case database.php:
'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'),
            ]) : [],
        ],


I would be very grateful for any help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-07-10
@q2digger

Where is the base located? In a container or on a host? Or on another server. Here is the address and specify and not 127.0.0.1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question