-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile
110 lines (91 loc) · 3.7 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
FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04
ARG USER_ID=1001
ARG GROUP_ID=101
ARG USER=app
ENV USER=$USER
ARG PROJ_ROOT=/$USER
USER root
RUN groupadd --gid $GROUP_ID $USER
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID $USER
RUN mkdir $PROJ_ROOT && chown $USER $PROJ_ROOT
WORKDIR $PROJ_ROOT
# These next two folders will be where we will mount our local data and out
# directories. We create them manually (automatic creation when mounting will
# create them as being owned by root, and then our program cannot use them).
RUN mkdir data && chown $USER data
RUN mkdir out && chown $USER out
# tzdata configuration stops for an interactive prompt without the env var.
# https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image
# https://stackoverflow.com/questions/51023312/docker-having-issues-installing-apt-utils/56569081#56569081
ENV TZ=Europe/London
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends -y \
tzdata
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
git \
libsm6 \
libxext6 \
libxrender-dev \
jq \
locales \
ffmpeg && \
rm -rf /var/lib/apt/lists/*
# Set the locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
###############################################################################
# Conda
###############################################################################
# Set up the Conda environment (using Miniforge)
ENV PATH=/home/$USER/mambaforge/bin:$PATH
#COPY environment.yml /app/environment.yml
RUN curl -sLo ./mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/22.9.0-1/Mambaforge-22.9.0-1-Linux-x86_64.sh \
&& chmod +x ./mambaforge.sh \
&& ./mambaforge.sh -b -p /home/$USER/mambaforge \
&& rm ./mambaforge.sh \
# && mamba env update -n base -f /app/environment.yml \
# && rm /app/environment.yml \
&& mamba clean -ya
###############################################################################
# /Conda
###############################################################################
RUN pip install --upgrade pip
RUN pip install -r pkg_requirements.txt
RUN pip install \
jupyterlab \
ipywidgets \
jupyterlab-vim \
jupyter-dash \
jupyterlab-spellchecker \
matplotlib \
pytest \
mypy \
dash
RUN conda install --yes -c conda-forge nodejs
# From: https://stackoverflow.com/questions/67050036/enable-jupyterlab-extensions-by-default-via-docker
COPY --chown=$USER tools/jupyter_notebook_config.py /etc/jupyter/
# Try to get Jupyter Lab to allow extensions on startup.
# This file was found by diffing a container running jupyterlab that had
# extensions manually enabled.
COPY --chown=$USER tools/plugin.jupyterlab-settings /home/$USER/.jupyter/lab/user-settings/@jupyterlab/extensionmanager-extension/
# Keyboard shortcuts
COPY --chown=$USER tools/shortcuts.jupyterlab-settings /home/$USER/.jupyter/lab/user-settings/@jupyterlab/shortcuts-extension/
# Getting some permission errors printed in terminal after running Jupyter Lab,
# and trying the below line to fix:
RUN chown -R $USER:$USER /home/$USER/.jupyter
RUN jupyter lab build # needed for Dash. Very annoying. Takes ages.
USER root
# In order to allow the Python package to be edited without
# a rebuild, install all code as a volume. We will still copy the
# files initially, so that things like the below pip install can work.
COPY --chown=$USER ./ ./
# Install our own project as a module.
# This is done so the tests and JupyterLab code can import it.
RUN pip install -e ./retinapy
# Switching to our new user. Do this at the end, as we need root permissions
# in order to create folders and install things.
USER $USER