How to build Dockerfile with R & Java

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 16:17:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/61390888/how-to-build-dockerfile-with-r-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!