Home > Mobile >  Installing R in a docker container
Installing R in a docker container

Time:04-21

I'm trying to install in a Ubuntu:20.04 based container miniconda and, using the conda keyword, R:4.05.

The Dockerfile I'm using is this:

FROM ubuntu:20.04
USER root
RUN apt-get update 
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev
RUN apt-get install -y wget 
RUN mkdir -p ~/miniconda3
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
RUN bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
RUN export PATH=~/miniconda3/bin:$PATH
RUN rm -rf ~/miniconda3/miniconda.sh
RUN ~/miniconda3/bin/conda init bash
RUN ~/miniconda3/bin/conda init zsh
RUN ~/miniconda3/bin/conda config --add channels conda-forge
RUN ~/miniconda3/bin/activate
RUN ~/miniconda3/bin/conda install -y -c conda-forge r-base

RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('DESeq2')"

From lines 8 to 16 I download miniconda and run it in ~/miniconda3

In line 17:

RUN R -e "install.packages('BiocManager')"

I try to use R and install the BiocManager package from the command line, but I receive this error:

 > [16/17] RUN R -e "install.packages('BiocManager')":
#19 2.767 /bin/sh: 1: R: not found
------
executor failed running [/bin/sh -c R -e "install.packages('BiocManager')"]: exit code: 127

I've also tried to start from the official distribution of Rocker, but in this way (the way I've shown you in this post) I would prefer it since I would end up with an image in which I have both miniconda and R.

Can someone help me? Thanks a lot!

CodePudding user response:

Each RUN command runs in a separate shell, so your export command sets the path, but then the shell exits and the path is reset for the next RUN command.

You also have to use the absolute path. Tilde expansion doesn't work.

Instead of

RUN export PATH=~/miniconda3/bin:$PATH

try

ENV PATH=/root/miniconda3/bin:$PATH
  • Related