-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
238 lines (213 loc) · 7.54 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
FROM jupyter/scipy-notebook:ubuntu-20.04
LABEL maintainer="Alice Lepissier <[email protected]>"
###### START Binder code ######
# from https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html
# Binder does not allow root container processes
# and ${NB_USER} will run the JupyterLab process on Binder
ARG NB_USER
ARG NB_UID
ENV USER ${NB_USER}
ENV NB_UID ${NB_UID}
ENV HOME /home/${NB_USER}
# To work on Binder, the contents of the repo must be in ${HOME}
COPY . ${HOME}/work
USER root
RUN chown -R ${NB_UID} ${HOME}
###### END Binder code ######
###### START R code ######
# from https://github.com/jupyter/docker-stacks/blob/master/r-notebook/Dockerfile
# R pre-requisites
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
fonts-dejavu \
unixodbc \
unixodbc-dev \
r-cran-rodbc \
gfortran \
gcc \
# libfontconfig1-dev is a dependency of kableExtra/systemfonts
libfontconfig1-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Fix for devtools https://github.com/conda-forge/r-devtools-feedstock/issues/4
RUN ln -s /bin/tar /bin/gtar
USER ${NB_UID}
# R packages including IRKernel which gets installed globally
RUN conda install --quiet --yes \
'r-base=4.1.3' \
'r-caret' \
'r-crayon' \
'r-devtools' \
# e1071 is a dependency of the caret R package
'r-e1071' \
'r-forecast' \
'r-hexbin' \
'r-htmltools' \
'r-htmlwidgets' \
'r-irkernel' \
'r-randomforest' \
'r-rcurl' \
'r-rmarkdown' \
'r-rodbc' \
'r-rsqlite' \
'r-shiny' \
'r-tidymodels' \
'r-tidyverse' \
# START new packages - maybe would be better in requirements.R
'r-here' \
#'r-feather' \
'r-ggridges' \
'r-janitor' \
'r-kableExtra' \
'r-lfe' \
'r-plm' \
'r-stargazer' \
'r-WDI' \
# END new packages
'unixodbc' && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Install R libraries
COPY ./requirements.R .
RUN Rscript requirements.R && rm requirements.R
###### END R code ######
###### START RStudio code ######
USER root
# Earlier RStudio version
# from https://github.com/riazarbi/datasci-gui-minimal/blob/a281fc00c1149cd2d472e117b451d73042ba9e32/Dockerfile
#ENV RSTUDIO_VERSION=1.4.1722
# Later RStudio version
# from https://github.com/riazarbi/datasci-gui-minimal/blob/focal/Dockerfile
ENV RSTUDIO_VERSION=2022.02.1-461
# Flag is needed to make RStudio work on JupyterLab
ENV RSESSION_PROXY_RSTUDIO_1_4=yes
# RStudio pre-requisites
# from https://support.rstudio.com/hc/en-us/articles/206794537-Common-dependencies-for-RStudio-Workbench-and-RStudio-Server
# and https://github.com/rocker-org/rocker-versioned2
# and https://github.com/riazarbi/datasci-gui-minimal/blob/focal/Dockerfile
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
bash-completion \
ca-certificates \
file \
gdebi-core \
libapparmor1 \
#libgc1c2 \
libblas-dev \
libc6 \
libclang-dev \
libbz2-* \
libcurl4 \
libcurl4-openssl-dev \
#libcurl4-gnutls-dev \
libedit2 \
libicu* \
libjpeg-turbo* \
liblapack-dev \
libobjc4 \
libpangocairo-* \
#libpcre2* \
libpng16* \
libpq5 \
#libpq-dev \
#libssl1.1 \
libssl-dev \
libtiff* \
#libuser \
#libuser1-dev \
liblzma* \
lsb-release \
procps \
psmisc \
python-setuptools \
rrdtool \
tree \
sudo \
wget \
zip unzip && \
apt-get clean && rm -rf /var/lib/apt/lists/*
ENV PATH=$PATH:/${NB_USER}/lib/rstudio-server/bin \
R_HOME=/opt/conda/lib/R
ARG LITTLER=${R_HOME}/library/littler
RUN \
# Install RStudio
# from https://github.com/radiant-rstats/docker/blob/master/files/install-rstudio.sh
# and https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_rstudio.sh
wget -q https://s3.amazonaws.com/rstudio-ide-build/server/bionic/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb && \
gdebi -n rstudio-server-${RSTUDIO_VERSION}-amd64.deb && \
rm rstudio-server-${RSTUDIO_VERSION}-amd64.deb && \
rm -rf /var/lib/apt/lists/* && \
# Set default CRAN mirror
echo -e "local({\n r <- getOption('repos')\n r['CRAN'] <- 'https://cloud.r-project.org'\n options(repos = r)\n })" > $R_HOME/etc/Rprofile.site && \
\
# Littler provides install2.r script
R -e "install.packages(c('littler', 'docopt'))" && \
\
# Modify littler scripts to conda R location
sed -i 's/\/${NB_USER}\/local\/lib\/R\/site-library/\/opt\/conda\/lib\/R\/library/g' \
${LITTLER}/examples/*.r && \
# Create symbolic links
ln -s ${LITTLER}/bin/r ${LITTLER}/examples/*.r /usr/local/bin/ && \
echo "${R_HOME}/lib" | sudo tee -a /etc/ld.so.conf.d/littler.conf && \
ldconfig && \
fix-permissions ${CONDA_DIR} && \
fix-permissions /home/${NB_USER}
###### END RStudio code ######
USER ${NB_USER}
###### START Jupyter code ######
# Jupyter notebook extensions & packages
RUN \
# Python packages
pip install lightgbm pyarrow feather-format papermill nested-cv \
openpyxl pyreadr networkx==2.5 joypy && \
\
# Install Jupyter Notebook extensions
pip install jupyter_contrib_nbextensions jupyter_nbextensions_configurator && \
jupyter contrib nbextension install --sys-prefix && \
# Enable GUI configurator for Jupyter Notebook extensions
# Known issue: configurator does not load with JupyterLab 3
# https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator/issues/127
#jupyter nbextensions_configurator enable --sys-prefix && \
\
# Enable extensions from jupyter_contrib_nbextensions
# from https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions
jupyter nbextension enable export_embedded/main --sys-prefix && \
jupyter nbextension enable hinterland/hinterland --sys-prefix && \
jupyter nbextension enable scratchpad/main --sys-prefix && \
jupyter nbextension enable toc2/main --sys-prefix && \
\
# https://rise.readthedocs.io/en/stable/installation.html
pip install RISE && \
jupyter nbextension enable rise --py --sys-prefix && \
\
# https://github.com/data-8/nbzip/blob/master/README.md
pip install nbzip && \
jupyter serverextension enable --py nbzip --sys-prefix && \
jupyter nbextension install --py nbzip --sys-prefix && \
jupyter nbextension enable --py nbzip --sys-prefix && \
\
# https://nbdime.readthedocs.io/en/latest/installing.html
pip install --upgrade nbdime && \
nbdime extensions --enable --sys-prefix
# Other Python packages
RUN conda install -y -c conda-forge cartopy && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
# Jupyter Lab extensions
# https://github.com/jupyterlab/jupyterlab-github
#RUN pip install jupyterlab_github
# Jupyter Server & RStudio configuration
# Documentation: https://github.com/jupyterhub/jupyter-server-proxy
# and https://github.com/jupyterhub/jupyter-rsession-proxy
# Known issues with RStudio and Jupyter described at
# https://github.com/jupyterhub/jupyter-rsession-proxy/issues/93
# and https://github.com/jupyterhub/jupyter-rsession-proxy/issues/95
RUN pip install jupyter-server-proxy==3.2.1 jupyter-rsession-proxy==2.0.1 && \
# Remove cache
rm -rf ~/.cache/pip ~/.cache/matplotlib ~/.cache/yarn && \
\
conda clean --all -f -y && \
fix-permissions ${CONDA_DIR} && \
fix-permissions /home/${NB_USER}
###### END Jupyter code ######