简体   繁体   English

使用 Docker 安装 rJava 包

[英]Installing rJava package with Docker

I am trying to install the 'rJava' package in my RStudio docker image using my Dockerfile :我正在尝试使用我的Dockerfile在我的RStudio docker映像中安装'rJava'包:

FROM rocker/tidyverse:3.6.1

RUN mkdir -p /rstudio
RUN mkdir -p /rscripts

RUN apt-get update && \
    apt-get install -y openjdk-11-jdk && \
    apt-get install -y liblzma-dev && \
    apt-get install -y libbz2-dev

RUN R -e "install.packages(c('rJava','mailR'))"

Following this SO post I added the above part with the apt-get commands but still I get the same error:在此SO 帖子之后,我使用apt-get命令添加了上述部分,但仍然出现相同的错误:

java libs : '-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm' checking whether Java run-time works... ./configure: line 3766: /usr/bin/java: No such file or directory no configure: error: Java interpreter '/usr/bin/java' does not work ERROR: configuration failed for package 'rJava' java libs:'-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm'检查Java运行时是否有效......./configure:第3766行:/usr /bin/java:没有这样的文件或目录没有配置:错误:Java 解释器“/usr/bin/java”不起作用错误:包“rJava”的配置失败

So there is a missing file or directory but I don't know what changes I should make.所以有一个丢失的文件或目录,但我不知道我应该做哪些更改。

[EDIT 1]: [编辑 1]:

So, following Dirk's suggestion, I entered in the rstudio container and ran apt-get install r-cran-rjava which seems to work.因此,按照 Dirk 的建议,我进入了 rstudio 容器并运行了apt-get install r-cran-rjava这似乎有效。
But when I install rJava package I get a new error:但是当我安装rJava包时,我收到一个新错误:

error: Cannot compile a simple JNI program.错误:无法编译简单的 JNI 程序。 Make sure you have Java Development Kit installed and correctly registered in R. If in doubt, re-run "R CMD javareconf" as root.确保您已安装 Java Development Kit 并在 R 中正确注册。如果有疑问,请以 root 身份重新运行“R CMD javareconf”。

I tried to enter again in the container and run R CMD javareconf but that did not change the error.我尝试再次进入容器并运行R CMD javareconf但这并没有改变错误。 I also tried the following commands found on this article :我还尝试了本文中的以下命令:

sudo apt-get install default-jre
sudo apt-get install default-jdk

But I still get:但我仍然得到:

Cannot compile a simple JNI program.无法编译简单的 JNI 程序。

This is a duplicate of similar answers I have already given in the Debian / Ubuntu context.这是我在 Debian / Ubuntu 上下文中已经给出的类似答案的重复。 The fact that you are using Docker does not matter: you should still simply install the binary!您使用 Docker 的事实并不重要:您仍然应该简单地安装二进制文件!

edd@rob:~$ docker run --rm -ti r-base bash
root@ef4bb9726a21:/# apt update -qq
73 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ef4bb9726a21:/# apt install --no-install-recommends -y r-cran-rjava                                  
Reading package lists... Done                                                                            
Building dependency tree                                                                                 
Reading state information... Done                                                                        
The following additional packages will be installed:                                          
  ca-certificates-java default-jre default-jre-headless java-common libasound2 libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdbus-1-3 libdrm-amdgpu1 libdrm-common
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libedit2 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 liblcms2-2 libllvm10 libnspr4 libnss3 libpciaccess0 libpcsclite1
  libsensors-config libsensors5 libsqlite3-0 libvulkan1 libx11-xcb1 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-sync1 libxdamage1 libxfixes3 libxi6 libxshmfence1 libxtst6 libxxf86vm1 libz3-4
  openjdk-11-jre openjdk-11-jre-headless                                                                 
[.... many lines skipped ....]
Running hooks in /etc/ca-certificates/update.d...

done.
done.
root@ef4bb9726a21:/# R

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
[...some lines skipped...]
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
> 

I found a github repo suggesting to add these steps in the Dockerfile before installing R package rJava and it worked:我发现一个 github repo 建议在安装 R 包rJava之前在 Dockerfile 中添加这些步骤并且它起作用了:

RUN apt-get -y update && apt-get install -y \
   default-jdk \
   r-cran-rjava \
   && apt-get clean \
   && rm -rf /var/lib/apt/lists/

The reason why Dirk's answer doesn't work for you is because you're using rocker/tidyverse as a base image instead of the r-base that Dirk is using. Dirk 的答案对您不起作用的原因是因为您使用的是rocker/tidyverse作为基础图像,而不是 Dirk 正在使用的r-base

In the rocker/tidyverse documentation on Docker Hub they are discouraging the use of apt install --no-install-recommends -y r-cran-rjava :在 Docker Hub 上的rocker/tidyverse文档中,他们不鼓励使用apt install --no-install-recommends -y r-cran-rjava

do not use apt-get install r-cran-* to install R packages on this stack.不要使用apt-get install r-cran-*在此堆栈上安装 R 包。 The requested R version and all R packages are installed from source in the version-stable stack.请求的 R 版本和所有 R 包都从版本稳定堆栈中的源代码安装。 Installing R packages from apt (eg the r-cran-* packages) will install the version of R and versions of the packages that were built for the stable debian release (eg debian:stretch), giving you a second version of R and different packages.从 apt 安装 R 包(例如 r-cran-* 包)将安装 R 的版本和为稳定的 debian 版本构建的包的版本(例如 debian:stretch),为您提供第二个 R 版本和不同的版本包。 Please install R packages from source using the install.packages() R function (or the install2.r script), and use apt only to install necessary system libraries (eg libxml2).请使用 install.packages() R 函数(或 install2.r 脚本)从源代码安装 R 包,并且仅使用 apt 安装必要的系统库(例如 libxml2)。 If you would prefer to install only the latest verions of packages from pre-built binaries using apt-get, consider using the r-base stack instead.如果您只想使用 apt-get 安装来自预先构建的二进制文件的最新版本的软件包,请考虑使用 r-base 堆栈。

Since rJava is supposed to be installed with apt install r-cran-rjava , but the rocker/... base images explicitly tell you not to do that, it looks like you will not be able to use rJava with any of the rocker/... base images..由于rJava应该与apt install r-cran-rjava一起apt install r-cran-rjava ,但是apt install r-cran-rjava rocker/...基本图像明确告诉您不要这样做,看起来您将无法将rJava与任何rJava rocker/...基本图像..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM