Структура каталогов durpal 8:
.
├── docker-compose.yml
├── dump
│ └── drupal.sql
├── sessions
└── www
└── core
└── site
└── modules
└── vendor
└── index.php
Конфигурация моей базы данных settings.php
$databases['default']['default'] = array (
'database' => 'drupal',
'username' => 'root',
'password' => 'test',
'prefix' => '',
'host' => '127.0.0.1',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
Мой код docker-compose.yml
version: "2"
services:
www:
image: drupal:8
ports:
- "8001:80"
volumes:
- ./www:/var/www/html/
depends_on:
- db
networks:
- default
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: drupal
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- /var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
PMA_HOST: db
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
Используя приведенный выше код, я могу подключить phpmyadmin к mysql и он работает нормально, но я не могу подключить Drupal к mysql и получаю сообщение об ошибке ниже:
PDOException: SQLSTATE [HY000] [2002] Соединение отклонено в /var/www/html/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php в строке 79 # 0 / var / www / html / core / lib /Drupal/Core/Database/Driver/mysql/Connection.php(420): PDO -> конструкция __ («mysql: host = 127 ....», «root», «test», Array) \ n # 1 / var / www / html / core / lib / Drupal / Core / Database / Database.php (371): Drupal \ Core \ Database \ Driver \ mysql \ Connection :: open (Array) \ n # 2 / var / www / html /core/lib/Drupal/Core/Database/Database.php(166): Drupal \ Core \ Database \ Database :: openConnection ('default', 'default') \ n # 3 [внутренняя функция]: Drupal \ Core \ База данных \ База данных :: getConnection ('default') \ n # 4 /var/www/html/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(79): call_user_func_array ('Drupal \\ Core \\ Dat. .. ', Array) \ n # 5 /var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal \ Component \ DependencyInjection \ PhpArrayContainer-> createService (Array,' database ' ) \ n # 6 / var / www / html / core / lib / Drupal / Componen t / DependencyInjection / PhpArrayContainer.php (260): Drupal \ Component \ DependencyInjection \ Container-> get ('база данных', 1) \ n # 7 / var / www / html / core / lib / Drupal / Component / DependencyInjection / PhpArrayContainer .php (62): Drupal \ Component \ DependencyInjection \ PhpArrayContainer-> resolServicesAndParameters (Array) \ n # 8 /var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal \ Component \ DependencyInjection \ PhpArrayContainer-> createService (Array, 'cache.container') \ n # 9 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(515): Drupal \ Component \ DependencyInjection \ Container- > get ('cache.container') \ n # 10 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(876): Drupal \ Core \ DrupalKernel-> getCachedContainerDefinition () \ n # 11 / var / www / html / core / lib / Drupal / Core / DrupalKernel.php (468): Drupal \ Core \ DrupalKernel-> initializeContainer () \ n # 12 / var / www / html / core / lib / Drupal / Core / DrupalKernel.php (664): Drupal \ Core \ DrupalKernel-> boot () \ n # 13 /var/www/html/index.php(19): Drupal \ Core \ DrupalKernel-> handle (Объект (Symfony \ Component \ HttpFoundation \ Request)) \ n # 14 {main}