I try to run a yii2 basic project with docker in ubuntu 18.04. This is my docker-compose.yml:
version: '2'
services:
php:
image: yiisoftware/yii2-php:7.1-apache
volumes:
- ~/projects/basic/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app:delegated
ports:
- 8000:80
links:
- mysql
mysql:
image: mysql:5.7
volumes:
- ~/projects/basic/.composer-docker/mysql:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_USER=app"
- "MYSQL_PASSWORD=secret"
- "MYSQL_DATABASE=app"
ports:
- '33061:3306'
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
environment:
PMA_HOST: mysql
MYSQL_USERNAME: app
MYSQL_ROOT_PASSWORD: secret
ports:
- 8080:80
volumes:
- /sessions
links:
- 'mysql:mysql'
and this is config/db.php:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=app',
'username' => 'app',
'password' => 'secret',
'charset' => 'utf8',
I use the same folder console/migrations like in the yii2 advanced. When I run command ./yii migrate, the error "Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] Connection refused'" is occured. In the another case when host=mysql I get error "Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known'". What I did wrong?