Your docker container should be able to bind its mysql port to any port on the VM. You do it with the -p VMPort:containerPort
option of docker run
.
https://docs.docker.com/engine/reference/run/#expose-incoming-ports
So this command
docker run -p 3306:3306 your-sql-container
Will publish the 3306 port of your container to the 3306 port of your VM.
At that point you should be able to hit your SQL with
Connection con = DriverManager.getConnection("jdbc:mysql://10.0.2.15:3306/databaseName","root","myrootpassword");
I used your VM address and the binded port on the VM. You should replace databaseName
with the actual name of your DB.