提问人:ramen 提问时间:11/13/2023 更新时间:11/13/2023 访问量:25
带有 Rstudio 和 conda 虚拟环境的 Docker - 无法加载 R 包
Docker with Rstudio & conda virtual env - unable to load R packages
问:
我有这个dockerfile:
# Use the rocker/rstudio image with R version 4.1.2
FROM rocker/rstudio:4.1.2
# Install deps
RUN apt-get update && apt-get install -y \
wget \
bzip2 \
bash-completion \
libxml2-dev \
zlib1g-dev \
libxtst6 \
libxt6 \
libhdf5-dev \
libcurl4-openssl-dev \
libssl-dev \
libfontconfig1-dev \
libcairo2-dev \
libudunits2-dev \
libgdal-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy the package list file into the container
COPY r-requirements.txt /tmp/r-requirements.txt
# Install R packages from the list
RUN echo "Checkpoint installing R packages" && \
while IFS= read -r line; do \
case "${line}" in \
*"==CRAN=="*) R -e "install.packages('${line%%==*}', repos='http://cran.rstudio.com/', dependencies=TRUE, version='${line##*==}')";; \
*"==GITHUB=="*) R -e "devtools::install_github('${line%%==*}')";; \
*"==BIOMGR=="*) R -e "BiocManager::install('${line%%==*}')";; \
esac \
done < /tmp/r-requirements.txt && \
echo "Checkpoint after installing R packages"
# Miniconda3 for Linux-x86_64
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
bash /tmp/miniconda.sh -b -p /opt/conda && \
rm /tmp/miniconda.sh
# Add Miniconda3 to the PATH
ENV PATH="/opt/conda/bin:${PATH}"
# Create a virtual environment r-reticulate.yml
COPY r-reticulate.yml /tmp/r-reticulate.yml
RUN conda env create -f /tmp/r-reticulate.yml && \
rm /tmp/r-reticulate.yml
# Expose RStudio port
EXPOSE 8787
# Set up entry point to run RStudio with conda environment activated
CMD ["bash", "-c", "source activate r-reticulate && /init"]
此 r-requirements.txt 文件:
tidyverse==2.0.0==CRAN==
ggplot2==3.4.1==CRAN==
reticulate==1.28==CRAN==
keras==2.11.0==CRAN==
caret==6.0-93==CRAN==
BiocManager==3.13==CRAN==
#Github packages
grimbough/rhdf5filters==GITHUB==
#Bioconductor packages
rhdf5==BIOMGR==
还有这个 r-reticulate.yml:
name: r-reticulate
channels:
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_gnu
- bzip2=1.0.8=h7f98852_4
- ca-certificates=2022.12.7=ha878542_0
- ld_impl_linux-64=2.39=hcc3a1bd_1
- libffi=3.4.2=h7f98852_5
- libgcc-ng=12.2.0=h65d4601_19
- libgomp=12.2.0=h65d4601_19
- libnsl=2.0.0=h7f98852_0
- libsqlite=3.40.0=h753d276_0
- libuuid=2.32.1=h7f98852_1000
- libzlib=1.2.13=h166bdaf_4
- ncurses=6.3=h27087fc_1
- openssl=3.0.7=h0b41bf4_1
- pip=22.3.1=pyhd8ed1ab_0
- python=3.8.15=h4a9ceb5_0_cpython
- readline=8.1.2=h0f457ee_0
- setuptools=65.6.3=pyhd8ed1ab_0
- tk=8.6.12=h27826a3_0
- wheel=0.38.4=pyhd8ed1ab_0
- xz=5.2.6=h166bdaf_0
- pip:
- h5py==3.7.0
- keras==2.11.0
- numpy==1.24.1
- tensorflow==2.11.0
我想构建一个 docker 容器,在其中我可以运行 RStudio 并从中启动 R 包。我还希望能够通过此 RStudio 实例中的网状包使用虚拟环境 r-reticulate。一旦我构建了容器,我无法通过 library() 加载 R 包,RStudio 会抛出一个错误,通知未安装此类包,但是安装的退出状态为 0,因此库应该在那里。
我想我可能搞砸了贝壳,但我无法自己弄清楚。将不胜感激,因为我没有在互联网上找到解决方案。我希望 R 包远离 env,env 仅适用于某些版本的 python 和 tensorflow。
在理想情况下,我希望可以从 RStudio 访问虚拟环境,但取决于用户的输入,例如他们是否传递 reticulate::use_condaenv(“r-reticulate”) 或不) - 这是我无法弄清楚的选项。
在不太理想的选项中,我希望在 init 上沿着 RStudio 激活 conda env - 这是我试图做出的选项,但无济于事。
将不胜感激。
.yml 和 .txt 文件 IRL 包含更多规范,这只是一个最小的 reprex。
答: 暂无答案
评论