rdockerdockerfile

Install specific version of R langauge (R4.x.x) on a docker image based on ubuntu


I have a docker file that successfully grabs R and installs it but whenever I run the docker file, it just takes the latest version of R. Now I want to install just specific version of R (R 4.2.3 to be exact) but i dont seem to find a easy nice solution

Please note my image has to be based on Ubuntu 20.04. I am aware of r.rocker series of images from docker hub.

Here is my docker file code for the reference:

FROM ubuntu:20.04

#ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -qq && apt-get -y install --no-install-recommends --no-install-suggests \
    ca-certificates software-properties-common gnupg2 gnupg1 \
    && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 \
    && add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

RUN apt-get -y install r-base r-base-dev

RUN apt-get -y --no-install-recommends install \
    curl \
    libxml2-dev \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    libsodium-dev

Solution

  • After looking at here and some trail and error, I finally made a generic docker image that all the R 4 versions can be installed on, just change the R version on ENV

    FROM ubuntu:20.04
    
    ENV R_VERSION=4.2.3 \
        DEBIAN_FRONTEND=noninteractive
    
    RUN apt-get update -qq && apt-get -y install --no-install-recommends \
        ca-certificates \
        build-essential \
        gfortran \
        libreadline-dev \
        xorg-dev \
        libbz2-dev \
        liblzma-dev \
        curl \
        libxml2-dev \
        libcairo2-dev \
        libsqlite3-dev \
        libmariadbd-dev \
        libpq-dev \
        libssh2-1-dev \
        unixodbc-dev \
        libcurl4-openssl-dev \
        libssl-dev \
        libsodium-dev \
        wget \
        && rm -rf /var/lib/apt/lists/*
    
    # Download and install R
    RUN wget -c https://cran.r-project.org/src/base/R-4/R-${R_VERSION}.tar.gz \
        && tar -xf R-${R_VERSION}.tar.gz \
        && cd R-${R_VERSION} \
        && ./configure \
        && make -j$(nproc) \
        && make install \
        && cd .. \
        && rm -rf R-${R_VERSION} R-${R_VERSION}.tar.gz