I try to figure out this problem since a long time now and I've got to admit that I'm out of responses.
Here is the case:
docker-compose.yml
version: "3"
services:
mysql:
image: mysql:8.0
container_name: mysql
hostname: mysql
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
env_file: .env
volumes:
- db-data:/var/lib/mysql
networks:
- internal
drupal:
build:
context: .
dockerfile: Dockerfile
container_name: drupal
depends_on:
- mysql
restart: unless-stopped
volumes:
- ./web:/var/www/html/web:rw
- ./vendor:/var/www/html/vendor:rw
- ./drush:/var/www/html/drush
- drupal-data:/var/www/html
- ./php-conf/php.ini:/usr/local/etc/php/php.ini
networks:
- internal
- external
webserver:
image: nginx:1.19.1-alpine
container_name: webserver
depends_on:
- drupal
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- drupal-data:/var/www/html
- ./web:/var/www/html/web:rw
- ./nginx-conf/snippets/self-signed.conf:/etc/nginx/conf.d/snippets/self-signed.conf
- ./nginx-conf/snippets/ssl-params.conf:/etc/nginx/conf.d/snippets/ssl-params.conf
- ./nginx-conf/sites-available/default.conf:/etc/nginx/conf.d/default.conf
- ./ca-certificates/qiminfo-docker.dev+4.pem:/etc/ssl/certs/qiminfo-docker.dev+4.pem
- ./ca-certificates/qiminfo-docker.dev+4-key.pem:/etc/ssl/private/qiminfo-docker.dev+4-key.pem
networks:
- external
networks:
external:
driver: bridge
internal:
driver: bridge
volumes:
drupal-data:
db-data:
Dockerfile (only for drupal container)
FROM drupal:8.9.2-fpm-alpine
RUN apk add mysql-client && apk add openssh
I manage all dependencies via the mounted files in volumes (it works nice btw), but when I run drush through my host machine or through the container it doesn't see the Drupal instance (neither root or database) and I get the classic error message in this case ...
In BootstrapHook.php line 32:
[Exception]
Bootstrap failed. Run your command with -vvv for more information.
But, I use the Dockerfile to get mysql-client installed on drupal container and to allow connection from drupal container to mysql container. And when I try to connect to mysql (which has 'mysql' hostname) container database it works !
➜ docker exec -it drupal sh
/var/www/html # mysql -u drupal -p drupal -h mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [drupal]>
The question is:
Why drush doesn't has access to mysql server container while mysql-cli does the job fine ?!
Please help T-T