Drupal 8 is not connecting to Mysql in Docker
I guess you should point your database connections to the hostname you created in docker-compose file. Can't be a localhost address as you registered:
$databases['default']['default'] = array ('database' => 'drupal','username' => 'root','password' => 'test','prefix' => '','host' => 'db', #here you point to the container's service name'port' => '3306', 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql','driver' => 'mysql',);
Replace loca ip address
'host' => '127.0.0.1',
by service docker name
'host' => 'db',