How to install R 3.4.4 in alpine - r

I am trying to install R in my alpine image of docker. Earlier I did install it in my ubuntu image using
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 \
&& add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/' \
&& apt-get update \ && apt-get install -y r-base
Nowhere I could find how to install it in alpine.
Any help would be appreciated.
My base image is python:3.7-alpine

R is available in Alpine community repositories, so it's just a matter of installing the proper package:
apk add R
For a more compact image you could start off a vanilla Alpine image, such as alpine:3.9, if you don't need Python specifically.
The latest R version available on Alpine is 3.5.1. The closest to 3.4.4 is 3.4.2, which is available in Alpine V3.7. In that case, start off Alpine V3.7:
$ docker run -it alpine:3.7
/ # apk add R
If you need R version 3.4.4 exactly, you may have to build it from source. Fortunately, there is an excellent ready made Dockerfile by Artem Klevtsov which does just that:
https://github.com/artemklevtsov/r-alpine/blob/master/release/Dockerfile
Simply replace the R version string to 3.4.4 and build the image - works great.
Edit:
Another option for using a specific R version, which build is not available for native Alpine, is enabling glibc support on the Alpine container.
Normally, Alpine builds on musl libc, which is a specialized libc implementation that is generally not compatible to glibc, which is the de-facto standard libc used by most other Linux distributions. With glibc installed, you should be able to run any general-purpose R Linux build on the Alpine container.
The following Dockerfile portion would enable glibc support, adding some 10MB to the Alpine container size:
# Based on: https://github.com/anapsix/docker-alpine-java
FROM alpine:3.7
ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.28-r0
RUN set -ex && \
apk --update add libstdc++ curl ca-certificates && \
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk && \
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib

Related

Docker does not find R despite pre-built layers

I create a docker image to run R scripts on a VM server with no access to the internet.
For the first layer I load R and all libraries
Dockerfile1
FROM r-base
## Needed to access R
ENV R_HOME /usr/lib/R
## install required libraries
RUN apt-get update
RUN apt-get -y install libgdal-dev
## install R-packages
RUN R -e "install.packages('dplyr',dependencies=TRUE, repos='http://cran.rstudio.com/')"
...
and create it
docker build -t mycreate_od/libraries -f Dockerfile1 .
Then I use this library layer to load the R script
Dockerfile2
FROM mycreate_od/libraries
## Create directory
RUN mkdir -p /home/analysis/
## Copy files
COPY my_script_dir /home/analysis/
## Run the script
CMD R -e "source('/home/analysis/my_script_dir/main.R')"
Create the analysis layer
docker build -t mycreate_od/analysis -f vault/Dockerfile2 .
On my master VM, this runs and suceeds, but on the fresh VM I get
docker run mycreate_od/analysis
R docker ERROR: R_HOME ('/usr/lib/R') not found - Recherche Google
From a previous bug search I have set the ENV variable in the Docker (see Dockerfile1),
but it looks like docker installs R on some other place.
Thanks to Dirk advice I managed to get it done using r-apt (see Dockerfile below).
The image get then built and can be run without the R_HOME error.
BTW much faster and with a significantly smaller resulting image.
FROM rocker/r-apt:bionic
RUN apt-get update && \
apt-get -y install libgdal-dev && \
apt-get install -y -qq \
r-cran-dplyr \
r-cran-rjson \
r-cran-data.table \
r-cran-crayon \
r-cran-geosphere \
r-cran-lubridate \
r-cran-sp \
r-cran-R.utils
RUN R -e 'install.packages("tools")'
RUN R -e 'install.packages("rgdal", repos="http://R-Forge.R-project.org")'
This is unfortunately a cargo-boat solution, as I am unable to explain why the previous Dockerfile failed.

Install tensorrt with custom plugins

I'm able to install the desired version of TensorRT from official nvidia guide (https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#maclearn-net-repo-install)
sudo apt-get update && \
apt-get install -y libnvinfer7=7.1.3-1+cuda10.2 libnvonnxparsers7=7.1.3-1+cuda10.2 libnvparsers7=7.1.3-1+cuda10.2 libnvinfer-plugin7=7.1.3-1+cuda10.2 libnvinfer-dev=7.1.3-1+cuda10.2 libnvonnxparsers-dev=7.1.3-1+cuda10.2 libnvparsers-dev=7.1.3-1+cuda10.2 libnvinfer-plugin-dev=7.1.3-1+cuda10.2 python3-libnvinfer=7.1.3-1+cuda10.2 && \
sudo apt-mark hold libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev python3-libnvinfer
But I need some custom plugins. Fortunately I found the desired and added to folder plugin
https://github.com/NVIDIA/TensorRT/tree/master/plugin and registered it.
Now I do not understand how to build and install tensorrt with added plugin.
On the official repo on github https://github.com/NVIDIA/TensorRT there is an instruction, but it describes steps to build a docker image with tensorrt.
So the question is how to build tensorrt with custom plugin and install it on ubuntu?
It's quite easy to "install" custom plugin if you registered it.
So the steps are the following:
Install tensorRT
sudo apt-get update && \
apt-get install -y libnvinfer7=7.1.3-1+cuda10.2 libnvonnxparsers7=7.1.3-1+cuda10.2 libnvparsers7=7.1.3-1+cuda10.2 libnvinfer-plugin7=7.1.3-1+cuda10.2 libnvinfer-dev=7.1.3-1+cuda10.2 libnvonnxparsers-dev=7.1.3-1+cuda10.2 libnvparsers-dev=7.1.3-1+cuda10.2 libnvinfer-plugin-dev=7.1.3-1+cuda10.2 python3-libnvinfer=7.1.3-1+cuda10.2 && \
sudo apt-mark hold libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev python3-libnvinfer
Note: I installed v.7.1.3.1 of tensorrt and cuda 10.2 if you want to install other version change it but be careful the version of tensorRT and cuda match in means that not for all version of tensorRT there is the version of cuda
Build the library libnvinfer_plugin.so.x.x.x as described at https://github.com/NVIDIA/TensorRT
Note: x.x.x is the version of library in my case is 7.1.3
Delete existing libraries at /usr/lib/x86_64-linux-gnu if you have x86 architecture or /usr/lib/aarch64-linux-gnu for arm64:
libnvinfer_plugin.so.7.1.3
libnvinfer_plugin.so.7
libnvinfer_plugin.so
Again file names depends on tensorRT version.
Copy the library libnvinfer_plugin.so.7.1.3 to folder /usr/lib/x86_64-linux-gnu if you have x86 architecture or /usr/lib/aarch64-linux-gnu for arm64
Make simlinks for libraries:
sudo ln -s libnvinfer_plugin.so.7
sudo ln -s libnvinfer_plugin.so.7 libnvinfer_plugin.so

How to install R from tar gz file

I have R in 3.6.3 version and I want to download 4.0.0 version. I downloaded from https://cran.r-project.org/src/base/R-4/ tar gz file but I have no idea how can I install it. Could you please give me a command which can install this R version from tar gz file ?
Install R from Source on Linux
You can find a detailed description for a range of different Linux systems here.
In short, you will need to run the following chain of commands:
First to install dependencies. This will depend on your Linux distribution. For Linux Mint, you can do
sudo apt-get build-dep r-base
Then, specify your desired R version
export R_VERSION=4.2.1
In a folder of your choice, download the .tar.gz (For versions other than 4.X, you may need to adjust the link)
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
To build and install, run from the same shell
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
make
sudo make install
In case the ./configure ... step does not work out, you may need to install the missing binaries individually by hand.
You can check the installation by running
/opt/R/${R_VERSION}/bin/R --version
and create a symlink
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
Done!
Your R installation will be in
/opt/R/${R_VERSION}

Docker - Rstudio - R old version running together

I'm working with docker since approximately a week and I don't understand some of the linking containers stuff.
I've downloaded from rocker, the latest images of Rstudio. It work nicely, everything is ok. I have one own made container with an old R version (let's say humm 3.1.0-1 for example). What I want to do is to use Rstudio from rocker with my own made R version. But this is where I don't understand. How it works ? Is it possible ? If I can do that that'll be awesome but I really don't understand how.
If someone have a solution, that'll be really great.
This is my dockerfile for my old R version :
#Get trusty version of ubuntu
FROM ubuntu:trusty
#We need to have https for cran
RUN apt-get -y update && apt-get -y install apt-transport-https
#We add the mirror directory to get older version packages
RUN echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list
#We clean and get authentication key
RUN apt-get clean && gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E084DAB9
#We add the key
RUN gpg -a --export E084DAB9 | apt-key add -
#We now update our lib
RUN apt-get -y update
# --> R PACKAGE INSTALLATION <--
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install r-base-core=3.1.0-1trusty0
RUN DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install r-doc-html=3.1.0-1trusty0
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install r-base-dev=3.1.0-1trusty0
#Check version
RUN R --version
I used : docker build -t r-basev3-1-0-1 . to build it and that works fine. It's just the link between rstudio and my container that I can't figure it out how to do it.
Thank's in advance,
Regards
I don't think it's possible (or easy) to link RStudio in one container to R in another container, as containers are supposed to be isolated from each other. The easiest thing to do is probably to build your own r-base image by modifying this file https://github.com/rocker-org/rocker/blob/master/r-base/Dockerfile (just need to change the version part I think) and then build your own rstudio image based on this customized image by modifying files in this folder https://github.com/rocker-org/rocker/tree/master/rstudio (change the FROM part to your own customized image).

Unable to install R/rmr2 on AWS EMR

Having spent around a week trying to install R and rmr2 on AWS-EMR, I am turning to you all for a little help. My bootstrap script is successfully installing R 2.14.1-1~lennycran.0 (thanks to JD Long's blog). When I am trying to install rmr2 I am having the classic dependency problem. Seems I have to install packages like Rcpp, RJSONIO, bitops, digest and 5 more. Because only an older Rcpp works with R 2.14.1, I am downloading a named version and installing it. How old, I don't know - I randomly tried a few versions and 0.8.9 worked. I will make a few more hit-and-trials.
sudo curl -o Rcpp.tar.gz http://cran.us.r-project.org/src/contrib/Archive/Rcpp/Rcpp_0.8.9.tar.gz
sudo R CMD INSTALL Rcpp.tar.gz
Now I am supposed to install the rest of the dependencies (How?)
And eventually rmr2 would be installed. I am using the following script, which, of course fails -
sudo wget --no-check-certificate -o rmr2.tar.qz -S -T 10 -t 5 http://goo.gl/dvBric
sudo R CMD INSTALL rmr2.tar.gz
My question is -
What should be a simple bootstrap script for installing the rest of the dependencies ("RJSONIO", "bitops", "digest", "functional", "stringr", "plyr", "reshape2", "caTools")? Do I have to worry about compatibility of those packages as well?
Here is my complete bootstrap.sh code -
#!/bin/bash
#debian R upgrade
gpg --keyserver pgpkeys.mit.edu --recv-key 06F90DE5381BA480
gpg -a --export 06F90DE5381BA480 | sudo apt-key add -
echo "deb http://streaming.stat.iastate.edu/CRAN/bin/linux/debian lenny-cran/" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get -t lenny-cran install --yes --force-yes r-base r-base-dev
sudo curl -o rmr2.tar.gz http://goo.gl/dvBric
sudo R CMD INSTALL rmr2.tar.gz <<<< Does not go beyond this.
set -e
bucket=muxxx-bisxxx-bucket
path=input.tar.gz
wget -S -T 10 -t 5 http://$bucket.s3.amazonaws.com/$path
mkdir -p /home/hadoop/contents
tar -C /home/hadoop/contents -xzf input.tar.gz
export HADOOP_CMD=/home/hadoop/bin/hadoop
export HADOOP_STREAMING=/home/hadoop/contrib/streaming/hadoop_streaming.jar
/home/hadoop/bin/hadoop fs -mkdir /home/hadoop/contents
/home/hadoop/bin/hadoop fs -put /home/hadoop/contents/* /home/hadoop/contents/
I have not resolved my problem on hand but I got a direction. I added the following line of code in the bootstrap script after R 2.14.1 installation and before rmr2 installation -
sudo Rscript -e 'install.packages(c("rJava", "Rcpp", "RJSONIO", "bitops", "digest", "functional", "stringr", "plyr", "reshape2", "caTools"), repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/")'
Currently the bootstrapping process breaks down at plyr, which I guess, is due to older version of Rcpp that I have.
I am closing this post.

Resources