owise
owise

Reputation: 1065

Dockerizing an app that uses mxnet package in R

I am dockerizing a shiny app that uses 'mxnet' package. After lots of efforts I concluded that I need to build and install the package instead of just installing it normally from the dmlc repos. Below is me simplified dockerfile that tries to build and install the mxnet:

FROM r-base:latest


RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev/unstable \
libxt-dev \
libssl-dev

# Download and install shiny server
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-   build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt)  && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os- build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb

# Here comes the installation of other required packages:
# .......



#*** Here comes the problamatic bit: building Installing mxnet
RUN sudo apt-get update
RUN sudo apt-get install -y build-essential git libatlas-base-dev libopencv-dev

RUN git clone --recursive https://github.com/dmlc/mxnet
RUN cd mxnet; make -j$(nproc)

RUN Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"

RUN cd R-package

RUN Rscript -e "library('devtools'); library('methods'); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"


RUN cd ..

RUN make rpkg


COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /myapp/* /srv/shiny-server/

EXPOSE 80

COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server.sh"]

After running this, I recieve an error saying:

can not cd to R-Package

Any help?

Upvotes: 2

Views: 202

Answers (1)

user2915097
user2915097

Reputation: 32216

Try with

RUN cd mxnet; make -j$(nproc)\ && Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"

your RUN cd .. will not do what you expect, it is the same as opening a terminal, doing cd abc/def and in another terminal, which is in /home/$USER, doing cd .., you will not be in abc.

You should group your RUN commands in order to limit the number of layers in your image, see

https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

Check also the WORKDIR directive in a Dockerfile

https://docs.docker.com/engine/reference/builder/#workdir

You can check what is correctly done (or not) by launching a shell

docker run -it your_image /bin/bash

and then check what is present or not.

Upvotes: 1

Related Questions