Search code examples
rdockerdockerfilerjava

How to build Dockerfile with R & Java


I'm trying to build a Docker container that runs R with the package RJava. I have tried the following code:

# Install R version 3.6.3
FROM rocker/tidyverse:3.6.3

# Make ~/.R
RUN mkdir -p $HOME/.R

# Install Ubuntu packages && then R packages
RUN install2.r --error \
         lubridate magrittr RPostgres DBI broom rlang rJava

However I get the following: installation of package ‘rJava’ had non-zero exit status.

Can anyone help me with this. I'm thinking that maybe it is because Java is not installed. Does anyone know how to install Java on this docker container?

I've tried adding the following to my dockerfile as per another post I found however I get the error saying 'The repository 'http://ppa.launchpad.net/webupd8team/java/ubuntu focal Release' does not have a Release file:

# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
    software-properties-common

# Add the "JAVA" ppa
RUN add-apt-repository -y \
    ppa:webupd8team/java

# Install OpenJDK-8
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
    apt-get install -y ant && \
    apt-get clean;

# Fix certificate issues
RUN apt-get update && \
    apt-get install ca-certificates-java && \
    apt-get clean && \
    update-ca-certificates -f;

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME

I'm new to docker and any help with this would be much appreciated.


Solution

  • The rocker images are based on debian, not ubuntu. Specifically it is Debian GNU/Linux 10 (buster). With that version, you can install java by installing the package openjdk-11-jdk via apt and you don't need to add any repositories for openjdk-8-jdk.

    So a working dockerfile that installs rJava:

    FROM rocker/tidyverse:3.6.3
    
    RUN apt-get update && \
        apt-get install -y openjdk-11-jdk && \
        apt-get install -y liblzma-dev && \
        apt-get install -y libbz2-dev
    
    RUN Rscript -e "install.packages('rJava')"
    

    Note: liblzma-dev and libbz2-dev are additional system dependencies for compiling rJava.