如何在R Docker映像中设置DBI和OBDC以通过DBI运行PSQL查询?

6l7fqoea  于 2023-02-26  发布在  Docker
关注(0)|答案(1)|浏览(235)

我试图找到一个安装了R、ODBC和DBI的Docker映像,但找不到任何映像,因此我创建了一个-anirbans96/rodbcdbi
现在,当我尝试使用psqlodbcw.so作为驱动程序在PostgresSQL上运行查询时,它会失败,因为它找不到驱动程序。然而,我将此文件从laudio/pyodbc:1.0.38 Docker映像'us/lib/x86_64-linux-gnu/odbc/psqlodbcw.so'复制到我的Docker映像上的相同位置。
但是,当我使用

DBI::dbConnect(
    odbc::odbc(),
    Server=server,
    Database=database,
    UID=user,
    PWD=password
)

它抛出错误:nanodbc/nanodbc.coo:1118: 0000: [unixODBC][Driver Manager] Can't open lib '/usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so' : file not found
我使用以下命令验证了文件是否存在:

if test -f "/usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so"; then
    echo "File Exists"
fi

我的文档-

FROM rocker/r-ubuntu

RUN apt-get update -y && apt-get install -y build-essential curl gnupg2 software-properties-common dirmngr apt-transport-https apt-utils lsb-release ca-certificates
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 apt-get update -y
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev mssql-tools 

# Install R packages (odbc R package must be installed AFTER installing ODBC in the OS)
RUN Rscript -e "install.packages('odbc')"
RUN Rscript -e "install.packages('DBI')"

# Copy and execute R script
# RUN mkdir /home/analysis
# COPY transformdata.r /home/analysis/transformdata.r
# CMD R -e "source('/home/analysis/transformdata.r')"

这已被推为anirbans96/rodbcdbi Dockerfile文件,我复制了pysqlodbc.so

FROM anirbans96/rodbcdbi
RUN mdkir /usr/lib/x86_64-linux-gnu/odbc/
COPY psqlodbcw.so /usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so

我们还需要配置什么?

hk8txs48

hk8txs481#

根据@r2evans的建议
我添加了apt-get odbc-postgresql postgresql-client,它解决了这个问题。
新的停靠文件如下所示:

FROM rocker/r-ubuntu

RUN apt-get update -y && apt-get install -y build-essential curl gnupg2 software-properties-common dirmngr apt-transport-https apt-utils lsb-release ca-certificates odbc-postgresql postgresql-client unixodbc-dev
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 Rscript -e "install.packages('odbc')"
RUN Rscript -e "install.packages('DBI')"
RUN Rscript -e "install.packages('stringr')"

这已作为新的anirbans96/rodbcdbi添加到Dockerhub

相关问题