Estou tentando subir um php-apache e fazer a conexão com o MySQL usando docker-compose:
Docker-compose.wml
version: "3.3"
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
php:
build: ./php
volumes:
- "./src/:/var/www/html/"
ports:
- 8082:80
links:
- db
index.php
<?php
$servername = "db";
$username = "root";
$password = "root";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Mensagem de erro retornada ao acessar localhost:8082
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'172.21.0.3' (using password: YES) in /var/www/html/index.php on line 14
Connection failed: Access denied for user 'root'@'172.21.0.3' (using password: YES)
Alguem sabe por que esta dando este problema, e o que fazer para corrigir?