mercoledì 8 novembre 2023

R 3.6 docker personalizzato

 Un esempio di Dockerfile complesso per R 3.6



FROM rstudio/r-base:3.6-bookworm

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update
RUN apt-get -y install gdal-bin libgdal-dev libpng-dev libudunits2-dev libfontconfig1-dev libmagick++-dev openjdk-17-jdk apache2 mc nano locales && apt-get clean




RUN service apache2 restart


#ENTRYPOINT ["/usr/sbin/apache2", "-k", "start"]
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]

CMD apachectl -D FOREGROUND

# installa client Oracle
RUN wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-23.2.0.178.1027.zip && unzip sqlcl*.zip
ENV PATH=sqlcl/bin:$PATH


#imposta la localizzazione italiana
RUN sed -i -e 's/# it_IT.UTF-8 UTF-8/it_IT.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG it_IT.UTF-8
ENV LANGUAGE it_IT:it
ENV LC_ALL it_IT.UTF-8

# imposta la timezone a Europe/Rome
ENV TZ="Europe/Rome"

# scarica il sorgente della libreria non presente su CRAN
RUN curl -O "https://cran.r-project.org/src/contrib/Archive/randomForest/randomForest_4.6-10.tar.gz"
#setup R configs
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'http://cran.us.r-project.org'; options(repos = r);" > ~/.Rprofile
RUN Rscript -e "install.packages('zoo')"
RUN Rscript -e "install.packages('leaflet')"
RUN Rscript -e "install.packages('sf')"
RUN Rscript -e "install.packages('leafpop')"
RUN Rscript -e "install.packages('forecast')"
RUN Rscript -e "install.packages('stringr')"
RUN Rscript -e "install.packages('lubridate')"
RUN Rscript -e "install.packages('randomForest_4.6-10.tar.gz', repos = NULL, type='source')"
RUN Rscript -e "install.packages('rpart')"
RUN Rscript -e "install.packages('e1071')"
RUN Rscript -e "install.packages('kknn')"
RUN Rscript -e "install.packages('jpeg')"
RUN Rscript -e "install.packages('data.table')"
RUN Rscript -e "install.packages('tidyr')"
RUN Rscript -e "install.packages('magick')"
RUN Rscript -e "install.packages('leaflet.extras')"
RUN Rscript -e "install.packages('leafem')"
RUN Rscript -e "install.packages('raster')"

# copia i file
ADD go.sh /root/go.sh
ADD omnia_apuane_spool.sql /root/omnia_apuane_spool.sql
ADD omnia_apuane.R /root/omnia_apuane.R
ADD omnia_arno.R /root/omnia_arno.R
ADD omnia_laguna.R /root/omnia_laguna.R

#crea folders in html
RUN mkdir /var/www/html/mappe
RUN mkdir /var/www/html/mappe/omnia_apuane
RUN mkdir /var/www/html/Acque
RUN mkdir /var/www/html/Acque/LAGUNA
RUN mkdir /var/www/html/Acque/ARNO
RUN mkdir /var/www/html/Acque/ARNO/bollettini


# per il ROracle
ADD instantclient-basic-linux.x64-21.11.0.0.0dbru.zip instantclient-basic-linux.x64-21.11.0.0.0dbru.zip
ADD instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip
# ATTENZIONE il comando ADD decompatta in automatico
# i file tar.gz. Per questo motivo la riga successiva usa COPY
COPY ROracle_1.3-2_R_x86_64-linux-gnu.tar.gz /root/ROracle_1.3-2_R_x86_64-linux-gnu.tar.gz

RUN unzip instantclient-basic-linux.x64-21.11.0.0.0dbru.zip -d /opt/oracle/
RUN unzip instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip -d /opt/oracle/

RUN apt-get install -y libaio1
ENV PATH="${PATH}:/opt/oracle/instantclient_21_11"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/oracle/instantclient_21_11"

RUN ldconfig

# compila ROracle
RUN Rscript -e 'install.packages("/root/ROracle_1.3-2_R_x86_64-linux-gnu.tar.gz",repos=NULL,type="source")'
RUN Rscript -e "install.packages('RCurl')"
RUN Rscript -e "install.packages('stringr')"


#cancella i file temporanei
RUN rm randomForest_4.6-10.tar.gz
RUN rm sqlcl*.zip
RUN rm /root/*.tar.gz
RUN rm /root/*.zip

Nessun commento:

Posta un commento

Dockerizza Flask

Un esempio semplice per inserire in un container Docker una applicazione Flask Partiamo da una semplice applicazione che ha un file app.py ...