简体   繁体   中英

unable to install R packages in Docker container

I have a task to deploy two docker containers sql server and R Studio Server with packages: rvest, odbc, rodbc, dbi. In my task I need to have both docker compose and Docker file, but I cannot import the libraries I installed.

docker-compose.yml


    version: '3.9'
    services:
    
      rstudio:
        build: ./docker/rstudio
        container_name: etl
        environment:
          - PASSWORD=yourpassword
        ports:
          - 8787:8787

Dockerfile


    FROM rocker/rstudio
    
    RUN apt-get clean all && \
      apt-get update && \
      apt-get upgrade -y && \
      apt-get install -y \
        python3-pip \
      && apt-get clean all && \
      apt-get purge && \
      rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    
    RUN /usr/local/lib/R/bin/R -e 'install.packages("ODBC", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
       /usr/local/lib/R/bin/R -e 'install.packages("RODBC", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
       /usr/local/lib/R/bin/R -e 'install.packages("DBI", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
       /usr/local/lib/R/bin/R -e 'install.packages("rvest", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")'

when I login to container at localhost:8787 (user:rstudio, password:yourpassword) I can't import any of the libraries:


    > library(rvest)
    Error: package or namespace load failed for ‘rvest’ in dyn.load(file, DLLpath = DLLpath, ...):
     unable to load shared object '/usr/local/lib/R/site-library/xml2/libs/xml2.so':
      libxml2.so.2: cannot open shared object file: No such file or directory
    > library(RODBC)
    Error: package or namespace load failed for ‘RODBC’ in dyn.load(file, DLLpath = DLLpath, ...):
     unable to load shared object '/usr/local/lib/R/site-library/RODBC/libs/RODBC.so':
      libodbc.so.2: cannot open shared object file: No such file or directory
    > library(ODBC)
    Error in library(ODBC) : there is no package called ‘ODBC’
    > .libPaths()
    [1] "/usr/local/lib/R/site-library" "/usr/local/lib/R/library"     
    > R.home()
    [1] "/usr/local/lib/R"

My questions:

  1. how can I install these libraries
  2. how can I install and run jupyter lab in the same container

Docker compose execution logs:

(base) 192-168-1-105:sandpit username$ docker-compose up
Creating etl ... done
Attaching to etl
etl        | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
etl        | [s6-init] ensuring user provided files have correct perms...exited 0.
etl        | [fix-attrs.d] applying ownership & permissions fixes...
etl        | [fix-attrs.d] done.
etl        | [cont-init.d] executing container initialization scripts...
etl        | [cont-init.d] 01_set_env: executing... 
etl        | skipping /var/run/s6/container_environment/HOME
etl        | skipping /var/run/s6/container_environment/PASSWORD
etl        | skipping /var/run/s6/container_environment/RSTUDIO_VERSION
etl        | [cont-init.d] 01_set_env: exited 0.
etl        | [cont-init.d] 02_userconf: executing... 
etl        | [cont-init.d] 02_userconf: exited 0.
etl        | [cont-init.d] done.
etl        | [services.d] starting services
etl        | [services.d] done.

The first error message is key:

unable to load shared object '/usr/local/lib/R/site-library/xml2/libs/xml2.so

These RSPM packages do not install system dependencies (as they can't, they are simple tar.gz archives; the site offers some help). You could either just nstall the pre-made binaries from Ubuntu ( r-cran-{odbc,rodbc,dbi,rvest} ) or take care of the system-dependencies via eg

apt install libxml2 libodbc1

taking care of the XML and ODBC libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM