Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile configuration for R - failing to load certain packages

Tags:

docker

r

I'm trying to load R into my docker container, through the docker file. Certain R packages fail to install, like rvest. I'm also installing NiFi & Python at the same time. Here's my dockerfile:

FROM apache/nifi

ADD run.sh .
COPY nifi-extracttext-nar-1.5.nar /opt/nifi/nifi-1.8.0/lib
USER root
RUN apt-get update
RUN apt-get install -y python3 python3-dev python3-pip
RUN pip3 install bs4
RUN pip3 install requests
RUN chmod 777 run.sh

# PROBLEM AREA (everything above works great)
RUN apt-get -y install r-base
RUN apt-get -y install libcurl4-openssl-dev
RUN apt-get install libcurl4-openssl-dev

#setup R configs

FROM r-base:latest
RUN Rscript -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org')"
RUN Rscript -e "install.packages('httr', repos = 'http://cran.us.r-project.org')"
RUN Rscript -e "install.packages('rvest', repos = 'http://cran.us.rproject.org')"

USER nifi

ENTRYPOINT ["./run.sh"]

Problem point is definitely installing R itself, plus the packages I want. What's the correct way to format the R package install? I originally pulled format from this link, but not so sure the Rscript is correct.

rvest seems to be a particular painpoint, here.

UDPDATE:

When I try to run my script after docker build/run, I get this error:

Error in library(httr) : there is no package called ‘httr’
Execution halted

ERROR: dependency ‘openssl’ is not available for package ‘httr’
* removing ‘/usr/local/lib/R/site-library/httr’

Why would this happen??? I've installed it through docker.


These are some of the errors:

The downloaded source packages are in
'/tmp/RtmpykICxP/downloaded_packages'
Warning messages:
1: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'openssl' had non-zero exit status
2: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'xml2' had non-zero exit status
3: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'httr' had non-zero exit status
4: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'rvest' had non-zero exit status

And:

ERROR: configuration failed for package ‘xml2’
* removing ‘/usr/local/lib/R/site-library/xml2’
ERROR: dependency ‘openssl’ is not available for package ‘httr’
* removing ‘/usr/local/lib/R/site-library/httr’
ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’
* removing ‘/usr/local/lib/R/site-library/rvest’

And:

ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’

I found these errors after crawling through the terminal and building the image.

like image 261
papelr Avatar asked Sep 06 '25 17:09

papelr


1 Answers

You need to install xml2, openssl packages for the OS:

RUN apt-get -y install xml2 openssl

NB that the -y specifies 'yes' to apt-get install, so you can delete

RUN apt-get install libcurl4-openssl-dev

as your previous line does the same thing.

You might also want to install dependencies for R packages e.g.

RUN Rscript -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org', dependencies=TRUE)"

Hope that helps.

like image 96
bruce.moran Avatar answered Sep 09 '25 17:09

bruce.moran