I'm trying to access a SQL Server on a local intranet with R, where R is loaded in a docker file with R-base.
On my desktop, I create a ODBC driver and it recognizes my windows credentials with the following:
odbcDriverConnect('driver={SQL Server};server=<serverName>;database=<dbName>;trusted_connection=yes')
Using R-base, after a lot of trial and error I was able to get RODBC installed, but I have no idea how to connect to this server.
Warning messages:
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
The DockerFile, which was built with a lot of trial and error. I'm sure much of it is redundant. Also I exposed ports which I found doing some research but I have no idea if they are needed to be exposed.
FROM openanalytics/r-base
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
libcairo2-dev \
libxt-dev \
libcurl4-gnutls-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0
# RODBC
RUN apt-get update && \
apt-get install -y --no-install-recommends \
unixodbc \
unixodbc-dev \
unixodbc \
unixodbc-dev \
r-cran-rodbc \
apt-transport-https \
libssl-dev \
libsasl2-dev \
openssl \
curl \
unixodbc \
gnupg \
libc6 libc6-dev libc6-dbg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#RUN curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev mssql-tools
EXPOSE 3838
EXPOSE 8787
Once I build the file, I enter R studio and use install.packages("RODBC")
How can I connect to the SQL server from the docker file?
----------Update
after creating a docker container with Ubuntu, I found that I was not able to ping the server name. I was however, able to ping the server ip address.
I modified the search string to ping the ip address, and changed the driver, as follows:
odbcDriverConnect('driver={ODBC Driver 17 for SQL Server};server=<serverName>;database=<dbName>;trusted_connection=yes')
This still did not work.