agstudy / rsqlserver

Sql Server driver database interface (DBI) driver for R. This is a DBI-compliant Sql Server driver based on the System.Data.SqlClient.
82 stars 30 forks source link

Support for Docker #29

Closed ruaridhw closed 6 years ago

ruaridhw commented 7 years ago

Build a Docker image that can be used to run the package on macOS, Linux and Windows in a self-contained environment.

Relates to #24 #16 #13

ruaridhw commented 7 years ago

The documentation for Linux and Windows also needs a refresh as there are several known issues with rClr on Mono and newer versions of .NET for Windows.

See jmp75/rClr#27 and jmp75/rClr#31 for rClr build errors on Linux and macOS

agstudy commented 7 years ago

Excellent idea! I will try to help on this.

agstudy commented 7 years ago

Excellent. That was very fast. Excellent.

ruaridhw commented 7 years ago

@agstudy would you like to test the docker help script so that it's easy enough to follow along?

Also, if you prefer using RStudio Server for easier interactivity over command line R, you can download these two files over the top of the current Dockerfile and then in docker.sh run:

docker build -t rsqlserver-rstudio . instead of docker pull ruaridhw/rsqlserver:latest

and replace rsqlserver-rstudio everywhere there is ruaridhw/rsqlserver

The RStudio server will then run as a service in the background and can be accessed at http://localhost:8787

Probably best to test both cases.

agstudy commented 7 years ago

I have tested the docker.sh.

I think it works , but I am not sure becuase I don't know how to test it now. PS: I have added me as a docker user: sudo usermod -aG docker $USER

ruaridhw commented 7 years ago

Sorry, I just mean trial the script so it's easy to understand and works as expected. You can run both images together or independently:

  1. Independently: Trial both images separately by:

    • Running the R session interactively (as per the last section in docker.sh) and issue any test R commands you like
    • The SQL Server image can be connected at host = localhost from any desktop client (eg. SSMS, Visual Studio, Navicat ...)
  2. Together: Run the R session interactively and library(rsqlserver) in your session. Then you can connect to the DB image with con <- dbConnect('SqlServer', host = 'mydb', dbname = 'rsqlserverdb', user = 'SA', password = 'P@ssw0rd1') as per the second last part.

agstudy commented 7 years ago

I tested the 2 last statements:

docker run --name testrsqlserver --link=mssqldb --rm ruaridhw/rsqlserver Rscript \
   -e "library(rsqlserver)" \
   -e "con <- dbConnect('SqlServer', host = 'mydb', dbname = 'rsqlserverdb', user = 'SA', password = 'P@ssw0rd1')" \
   -e "dbReadTable(con, 'Inventory')"

Works fine and give the expecte dresult :


  id   name quantity
1  1 banana      150
2  2 orange      154

Then I tested the intercative R session and it works fine also:

docker rm rsqlserver122
docker run --name rsqlserver122 --link=mssqldb -i ruaridhw/rsqlserver

Excellent job!

agstudy commented 7 years ago

Now, How I can call the rsqlserver from Rstudio session?

ruaridhw commented 7 years ago

Do you mean your local RStudio installation? It's exactly as on the R image except for host:

con <- dbConnect('SqlServer', host = 'localhost', dbname = 'rsqlserverdb', user = 'SA', password = 'P@ssw0rd1')

Since I'm on a Mac, I can't run rsqlserver on my local RStudio so I have to run RStudio Server on a Docker image. That's what I was referring to here