Running VirtualBox with Ubuntu 16.04 on which I have a Docker container that has Apache2 and PHP installed.
MYSQL is installed on the host(ubuntu on VirtualBox).
I am trying to access the MYSQL server on host from the docker container
<?php
$host = '192.168.136.101';
$user = 'root';
$pass = '****';
$db = 'test';
$port = '3306';
$con = mysqli_connect($host,$user,$pass,$db,$port);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
I get a connection refused notice.
when starting the container I have tried
docker run -ti -p 80:80 -p 3306:3306 IMAGE
Which doesn't work as port 3306 is being used by MYSQL server on host and if I stop MYSQL server on host the docker run command executes however I am then unable to start MYSQL service on host
I have also tried
docker run -ti -p 80:80 --add-host=database:192.168.136.101 IMAGE
and changed the bind address in /etc/mysql/mysql.conf.d/mysqld.cnf accordingly
still no luck
Thanks