-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile.cpu
More file actions
98 lines (78 loc) · 3.22 KB
/
Dockerfile.cpu
File metadata and controls
98 lines (78 loc) · 3.22 KB
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
# CPU-only pip-based image
FROM ubuntu:24.04
ENV SHELL=/bin/bash
# Don't buffer Python stdout/stderr output
ENV PYTHONBUFFERED=1
# Don't prompt in apt commands
ENV DEBIAN_FRONTEND=noninteractive
# persistent install for vscode extensions
ENV CODE_EXTENSIONSDIR=/opt/share/code-server
# Redirect XDG config out of $HOME so it survives JupyterHub volume mounts
ENV XDG_CONFIG_HOME=/opt/share/xdg-config
# Set up JupyterLab user
ARG NB_USER=jovyan
ENV NB_USER=${NB_USER}
ENV NB_UID=1000
ENV USER="${NB_USER}"
ENV HOME="/home/${NB_USER}"
ENV LANG=en_US.UTF-8
# Set up system-wide Python virtual environment
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
USER root
# Ubuntu 24.04 base has ubuntu user/group at UID/GID 1000, rename to jovyan
RUN groupmod -n ${NB_USER} ubuntu && \
usermod -l ${NB_USER} -d /home/${NB_USER} -m ubuntu
# Install Python 3.12 (default in Ubuntu 24.04) and system dependencies
RUN apt-get update && apt-get install -y \
python3 \
python3-venv \
python3-pip \
git \
curl \
build-essential \
locales \
&& rm -rf /var/lib/apt/lists/*
# IMPORTANT: All pip installs and the final chown must stay in ONE RUN command.
# - pip installs run as root so jovyan cannot hit permission errors upgrading packages
# (e.g. setuptools) that root installed earlier in the same layer.
# - chown transfers ownership to jovyan AFTER all installs complete, so later
# pip installs run as jovyan can freely update any package.
# - chown in a SEPARATE RUN layer would duplicate every venv file, doubling image size.
COPY requirements-cpu.txt /tmp/requirements.txt
RUN python3 -m venv $VIRTUAL_ENV && \
pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r /tmp/requirements.txt && \
chown -R $NB_USER:$NB_USER $VIRTUAL_ENV
# install vscode
RUN curl -fsSL https://code-server.dev/install.sh | sh
# apt utilities, code-server setup
RUN curl -s https://raw.githubusercontent.com/rocker-org/ml/refs/heads/master/install_utilities.sh | bash
## Grant user sudoer privileges
RUN apt-get update && apt-get -y install sudo && \
usermod -aG sudo "$NB_USER" && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers
# Install R
COPY install_r.sh install_r.sh
RUN bash install_r.sh
# RStudio
COPY install_rstudio.sh install_rstudio.sh
RUN bash install_rstudio.sh
COPY Rprofile /usr/lib/R/etc/Rprofile.site
## Add rstudio's binaries to path for quarto
ENV PATH=$PATH:/usr/lib/rstudio-server/bin/quarto/bin
## Ensure RStudio has access to environment variables
COPY --chown=${NB_USER}:${NB_USER} set_renviron.sh /tmp/set_renviron.sh
RUN bash /tmp/set_renviron.sh
WORKDIR /home/$NB_USER
USER $NB_USER
COPY --chown=${NB_USER}:${NB_USER} vscode-extensions.txt /tmp/vscode-extensions.txt
RUN xargs -n 1 code-server --extensions-dir ${CODE_EXTENSIONSDIR} --install-extension < /tmp/vscode-extensions.txt
USER root
COPY install_llms.sh install_llms.sh
RUN bash install_llms.sh
USER $NB_USER
# When run at build-time, install.r automagically handles any necessary apt-gets
COPY --chown=${NB_USER}:${NB_USER} install.r /tmp/install.r
RUN Rscript /tmp/install.r
EXPOSE 8888
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--NotebookApp.token=''", "--NotebookApp.password=''"]