I have downloaded MYSQL docker image . Now trying to connect to MYSQL using host given in the IPaddress section of Docker inspect (say “172.17.0.2” ), port 3306 , username :root , and database : mysql.
I am trying to run an R script , where in I have placed the following Database connection ::
con <- dbConnect(RMySQL::MySQL(), dbname = “mysql”, host=“172.17.0.2”, port=3306,
username = “root”, password = )
But getting error , stating the host does not exist.
I even tried using various options of host like “localhost”. But still failing to connect stating ,
Error in .local(drv, …) :
Failed to connect to database: Error: Can’t connect to MySQL server on ‘172.17.0.2’ (0)
Calls: dbConnect -> dbConnect -> .local -> .Call
Please give us more information: What system are you using (Linux, Windows…), how do you start the MySQL container, where is the R script running (on the host or in a container)?
In general, you shouldn’t have to inspect a container. The IP you see there is an internal address that you don’t need to access the database.
I have installed docker quickstart terminal on Oracle Virtual Box (VM).
R script is placed in a local directory in my windows desktop.
I am logging in thru docker quickstart terminal , and going to the path in which the R script is placed , in my local desktop , through the quick start terminal using cd
then I am running the rscript (say test.R) by using
Rscript test.R
Please note , the test.R has the db connectivity to mysql as follows :------
also , mysql container has been created aftre pulling the latest mysql image from docker hub
aftre doing cd to the path , where the r script is placed , whenever I am tryin to run using
Rscript test.R , that time ,it s showing the error of not connecting to the host.