Bom dia!
Estou recebendo a mensagem de erro abaixo:
PDOException Object ( [message:protected] => SQLSTATE[HY000] [2002] No route to host [string:Exception:private] => [code:protected] => 2002 [file:protected] => /var/www/html/funcoes.php [line:protected] => 7 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/funcoes.php [line] => 7 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=172.21.0.2;dbname=empresa [1] => root [2] => q1w2e3r4 ) ) [1] => Array ( [file] => /var/www/html/index.php [line] => 6 [args] => Array ( [0] => /var/www/html/funcoes.php ) [function] => include ) ) [previous:Exception:private] => [errorInfo] => )
Servidor Linux Centos 8, rodando em cima de um Virtual Box.
Já ajustei o arquivo bancodedados.php e está configurado assim:
$host = "172.21.0.2";
$usuario = "root";
$senha = "q1w2e3r4";
$banco = "empresa";
Já tentei colocar o IP de Gateway citado no inspect abaixo, mas também não funcionou.
Rodei o inspect no container do MYSQL e há estas informações:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "9328ba097eb97684fa2e48d44749e673b3fa94162da30208789316e062d5d9f9",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3306/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3306"
}
],
"33060/tcp": null
},
"SandboxKey": "/var/run/docker/netns/9328ba097eb9",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"curso-kubernetes-master_production-network": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"db",
"92e460db5384"
],
"NetworkID": "a5d0b653b923b119ae48fd9a35ad23f8d5fafbd67c189c6cee6599008ae89548",
"EndpointID": "555af3b8fd8258a3cce22418e88e2d539cbf343c04f429ee87ff54e8a641d1a0",
"Gateway": "172.21.0.1",
"IPAddress": "172.21.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:15:00:02",
"DriverOpts": null