My docker-compose looks like:
version: '3.4'
services:
php-fpm:
build:
context: ./docker
dockerfile: Dockerfile
target: php-fpm
ports:
- 443:443
volumes:
- .:/var/www/html
env_file:
- .env
mysql:
image: mysql:8.0
command:
- --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql-data:/var/lib/mysql
env_file:
- .env
ports:
- 3306:3306
My config/packages/doctrine.yaml looks like:
doctrine:
dbal:
dbname: testdb
host: 'mysql'
port: 3306
user: root
password: root
driver: pdo_mysql
server_version: '8.0'
unix_socket: /tmp/mysql.sock
My .env file looks like:
#SQL
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=testdb
MYSQL_USER=user
MYSQL_PASSWORD=pass
When I am trying to execute the following command:
sudo docker-compose exec php-fpm bin/console doctrine:migrations:migrate
I am getting the following error:
In AbstractMySQLDriver.php line 112:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
In Exception.php line 18:
SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 38:
SQLSTATE[HY000] [2002] Connection refused
Why?
PS. When I bash into mysql container and type command:
mysql -u root -proot
Everything is fine!