skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. You could invert the problem and start from the appropriate Docker images:

    $ docker run --rm -ti r-base:4.4.1 R --version | head -1
    R version 4.4.1 (2024-06-14) -- "Race for Your Life"
    $ docker run --rm -ti r-base:4.3.3 R --version | head -1
    R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
    $ docker run --rm -ti r-base:4.2.3 R --version | head -1
    R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
    $ docker run --rm -ti r-base:4.1.3 R --version | head -1
    R version 4.1.3 (2022-03-10) -- "One Push-Up"
    $ docker run --rm -ti r-base:4.0.5 R --version | head -1
    R version 4.0.5 (2021-03-31) -- "Shake and Throw"
    $ 
    

    The r-base images go back to a few more R 3.* versions if you need those.

    Edit If you are on Ubuntu and have the CRAN mirror of Ubunty binaries configure then you can point at 4.2.3 via a version constraint. I am on 24.04 and I don’t see 4.2.3 but I do see 4.3.1. An older base may see 4.2.3. Worst case … you can use a from-source installation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search