I'm trying to create a multi-stage build for an R application based on rocker/r-ubuntu:20.04
image.
The reason that I'm based on that image is to install binary packages via apt-get
as suggested in order to improve building time.
If I build the image without multi-stage build, the final image size is 2.32GB
, so i need to decrease the final size with multi-stage build.
The approach that I follow is create an alpine:latest
image and copy the app
folder from builder, and the R libraries installed (/usr/local/lib/R/site-library/
) and the binaries packages located in /usr/share/doc
.
The final image doesn't work, because no commands to execute the app is installed.
The Dockerfile is the following:
FROM rocker/r-ubuntu:20.04 as builder
# # system libraries of general use
RUN apt-get update && apt-get install -y \
pandoc \
...
libxml2-dev
RUN apt-get update && \
apt-get install -y -qq \
r-cran-config \
...
r-cran-tidyverse
RUN R -e "install.packages(c('other-packages'), dependencies=T)"
# copy the app to the image
RUN mkdir -p /root/bloomapp/tmp
COPY . /root/bloomapp
COPY .Renviron Rprofile.site /usr/lib/R/etc/
FROM alpine:latest
#Copy app to alpine
COPY --from=builder /root/bloomapp /root/bloomapp
COPY --from=builder /usr/local/lib/R/site-library/ /usr/local/lib/R/site-library/
COPY --from=builder /usr/share/doc /usr/share/doc
WORKDIR /root/bloomapp/
EXPOSE 3838
Is reasonable this approach? or exist any other better way to do multi-stage build for a R app image?
Thanks.