|
| 1 | +FROM jupyter/r-notebook:hub-4.0.1 |
| 2 | + |
| 3 | +USER root |
| 4 | + |
| 5 | +# Set up package manager |
| 6 | +RUN apt-get install -y apt-transport-https && \ |
| 7 | + apt-get clean && apt-get update && apt-get install -y software-properties-common && \ |
| 8 | + add-apt-repository multiverse && \ |
| 9 | + apt-get clean && rm -rf /var/lib/apt/lists/* |
| 10 | + |
| 11 | +# Install some base software |
| 12 | +RUN apt-get update --yes && \ |
| 13 | + apt-get install --yes \ |
| 14 | + fonts-dejavu \ |
| 15 | + unixodbc \ |
| 16 | + unixodbc-dev \ |
| 17 | + r-base \ |
| 18 | + r-cran-rodbc && \ |
| 19 | + apt-get clean && rm -rf /var/lib/apt/lists/* |
| 20 | + |
| 21 | +# Add sudo to jovyan user |
| 22 | +RUN apt update && \ |
| 23 | + apt install -y sudo && \ |
| 24 | + apt clean && \ |
| 25 | + rm -rf /var/lib/apt/lists/* |
| 26 | + |
| 27 | +# This is where we can control which root permissions the jovyan user will have |
| 28 | +ARG PRIV_CMDS='/bin/ch*,/bin/cat,/bin/gunzip,/bin/tar,/bin/mkdir,/bin/ps,/bin/mv,/bin/cp,/usr/bin/apt*,/usr/bin/pip*,/bin/yum,/opt,/opt/conda/bin/*,/usr/bin/*' |
| 29 | + |
| 30 | +RUN usermod -aG sudo jovyan && \ |
| 31 | + echo "$LOCAL_USER ALL=NOPASSWD: $PRIV_CMDS" >> /etc/sudoers |
| 32 | +RUN addgroup jovyan |
| 33 | +RUN usermod -aG jovyan jovyan |
| 34 | + |
| 35 | +# Install RStudio |
| 36 | +RUN apt-get update && apt-get install --yes gdebi-core && \ |
| 37 | + wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.09.1-494-amd64.deb && \ |
| 38 | + gdebi -n rstudio-server-2023.09.1-494-amd64.deb && \ |
| 39 | + rm rstudio-server-2023.09.1-494-amd64.deb && \ |
| 40 | + apt-get clean && rm -rf /var/lib/apt/lists/* |
| 41 | + |
| 42 | +# Install Geospatial libraries |
| 43 | +RUN apt-get update && \ |
| 44 | + apt install -y \ |
| 45 | + gdal-bin \ |
| 46 | + lbzip2 \ |
| 47 | + libfftw3-dev \ |
| 48 | + libgdal-dev \ |
| 49 | + libgeos-dev \ |
| 50 | + libgsl0-dev \ |
| 51 | + libgl1-mesa-dev \ |
| 52 | + libglu1-mesa-dev \ |
| 53 | + libhdf4-alt-dev \ |
| 54 | + libhdf5-dev \ |
| 55 | + libjq-dev \ |
| 56 | + libpq-dev \ |
| 57 | + libproj-dev \ |
| 58 | + libprotobuf-dev \ |
| 59 | + libnetcdf-dev \ |
| 60 | + libsqlite3-dev \ |
| 61 | + libudunits2-dev \ |
| 62 | + lsb-release \ |
| 63 | + netcdf-bin \ |
| 64 | + postgis \ |
| 65 | + protobuf-compiler \ |
| 66 | + sqlite3 \ |
| 67 | + tk-dev \ |
| 68 | + libfmt-dev \ |
| 69 | + unixodbc-dev && \ |
| 70 | + apt-get clean && rm -rf /var/lib/apt/lists/* |
| 71 | + |
| 72 | +# Fix RStudio / Conda openssl version mismatch |
| 73 | +RUN wget https://www.openssl.org/source/openssl-3.2.0.tar.gz && \ |
| 74 | + tar xfz openssl-3.2.0.tar.gz && \ |
| 75 | + mkdir openssl-build && cd openssl-build && \ |
| 76 | + ../openssl-3.2.0/Configure --libdir=/lib/x86_64-linux-gnu/ && \ |
| 77 | + make && \ |
| 78 | + make install |
| 79 | + |
| 80 | +# Update permissions for /opt/conda |
| 81 | +RUN mkdir /usr/local/bin/start-notebook.d && \ |
| 82 | + chown -R jovyan:users /opt/conda/share /usr/local/share /usr/local/bin/start-notebook.d |
| 83 | + |
| 84 | +USER jovyan |
| 85 | + |
| 86 | +# Install jupyterlab and rstudio dependencies |
| 87 | +RUN conda install -c conda-forge \ |
| 88 | + jupyter_client \ |
| 89 | + jupyter_core \ |
| 90 | + jupyterlab_server \ |
| 91 | + jupyter_server \ |
| 92 | + r-rgl \ |
| 93 | + r-htmlwidgets \ |
| 94 | + r-htmltools && \ |
| 95 | + jupyter lab clean |
| 96 | + |
| 97 | +# reinstall R packages. Here is where you add any new R packages you would like to install |
| 98 | +RUN mamba install --quiet --yes \ |
| 99 | + r-base \ |
| 100 | + r-tidyverse \ |
| 101 | + r-terra \ |
| 102 | + r-future \ |
| 103 | + r-future.apply \ |
| 104 | + r-furrr \ |
| 105 | + && \ |
| 106 | + mamba clean --all -f -y |
| 107 | + |
| 108 | +# Install Jupyter Lab Proxy extensions (cards in Launcher) |
| 109 | +RUN pip install jupyter-rsession-proxy jupyter-server-proxy jupyter-shiny-proxy jupyterlab-git |
| 110 | + |
| 111 | +# Install Mamba Gator package manager |
| 112 | +RUN rm -f ~/.jupyter/lab/workspaces/default* && \ |
| 113 | + mamba install -y -c conda-forge mamba_gator |
| 114 | + |
| 115 | +# Install and configure jupyter lab |
| 116 | +COPY jupyter_notebook_config.json /opt/conda/etc/jupyter/jupyter_notebook_config.json |
| 117 | + |
| 118 | +# Rebuild the Jupyter Lab with new tools |
| 119 | +RUN jupyter lab build |
| 120 | + |
| 121 | +# Build Conda environment. Any packages you would like to install with conda need to be added to the environment.yml file in this Dockerfiles directory |
| 122 | +RUN conda update -y conda && \ |
| 123 | + conda config --remove channels conda-forge && \ |
| 124 | + conda config --add channels conda-forge |
| 125 | +WORKDIR /home/jovyan |
| 126 | +COPY environment.yml /home/jovyan/ |
| 127 | +RUN mamba env create -f /home/jovyan/environment.yml |
| 128 | +RUN . /opt/conda/etc/profile.d/conda.sh && conda deactivate && conda activate custom && python -m ipykernel install --name custom && pip install jupyter_contrib_nbextensions |
| 129 | + |
| 130 | +# Install R packages from CRAN and GitHub |
| 131 | +RUN R -e "remotes::install_github('tomroh/ecoregions')" |
| 132 | +RUN R -e "install.packages('mblm', repos='http://cran.rstudio.com/')" |
| 133 | + |
| 134 | +# Set any required environment variables |
| 135 | +ENV PROJ_LIB=/opt/conda/envs/custom/share/proj |
| 136 | +RUN echo "PROJ_LIB=/opt/conda/envs/custom/share/proj" > /home/jovyan/.Renviron |
0 commit comments