jupyter/python/Dockerfile

61 lines
2.3 KiB
Docker
Raw Normal View History

ARG BASE_IMAGE
FROM ${BASE_IMAGE}
2024-03-17 15:40:43 +08:00
2024-04-13 13:25:50 +08:00
EXPOSE 8888
2024-03-17 15:40:43 +08:00
USER root
2024-04-11 22:09:41 +08:00
# Configure environment
ENV DEBIAN_FRONTEND=noninteractive \
NB_USER=jovyan \
NB_UID=1000 \
NB_GID=100 \
2024-10-16 16:31:16 +08:00
SHELL=/bin/bash \
2024-04-11 22:09:41 +08:00
PATH="/opt/base/bin:${PATH}" \
HOME="/home/jovyan"
2024-04-11 22:09:41 +08:00
2024-10-16 16:31:16 +08:00
# start script
COPY start-sh/* /usr/local/bin/
# jupyter config (to disable hide files) & healthcheck script
COPY jupyter_server_config.py docker_healthcheck.py /etc/jupyter/
# shell profile , to disable PATH be overwrited by jupyter
COPY profile /etc/
2024-04-11 22:09:41 +08:00
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
2024-10-11 09:45:04 +08:00
# install base packages
2024-10-05 14:15:26 +08:00
apt-get update --yes && apt-get install --yes --no-install-recommends sudo tini unzip python3-venv && \
2024-04-11 22:09:41 +08:00
apt-get clean && rm -rf /var/lib/apt/lists/* && \
chmod a+rx /usr/local/bin/* && \
# disable super permision
echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
sed -i.bak -e 's/^%admin/#%admin/' /etc/sudoers && \
sed -i.bak -e 's/^%sudo/#%sudo/' /etc/sudoers && \
2024-10-11 09:45:04 +08:00
# Create user , set password and add to sudoers
useradd --no-log-init --create-home --shell /bin/bash --uid "${NB_UID}" --no-user-group "${NB_USER}" && \
echo "${NB_USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
2024-04-11 22:09:41 +08:00
chmod g+w /etc/passwd && \
2024-10-11 09:45:04 +08:00
# Create dirs for startup hooks
2024-09-26 02:23:46 +08:00
mkdir /usr/local/bin/start-notebook.d && mkdir /usr/local/bin/before-notebook.d && \
2024-10-11 09:45:04 +08:00
# setup base venv & pip_mirror
2024-10-05 14:15:26 +08:00
mkdir -p "/opt/base/" && python3 -m venv /opt/base && chown -hR "${NB_USER}:${NB_GID}" "/opt/base" && \
2024-09-26 02:23:46 +08:00
echo '[global]\nindex-url = https://mirrors.bfsu.edu.cn/pypi/web/simple' > /etc/pip.conf
2024-04-11 22:09:41 +08:00
# HEALTHCHECK documentation: https://docs.docker.com/engine/reference/builder/#healthcheck
# This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server`, and `retro` jupyter commands
# https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799
HEALTHCHECK --interval=3s --timeout=1s --start-period=3s --retries=3 \
CMD /etc/jupyter/docker_healthcheck.py || exit 1
2024-04-11 22:09:41 +08:00
USER ${NB_UID}
2024-10-11 09:45:04 +08:00
# install jupyter extension
2024-04-12 16:10:40 +08:00
RUN pip install 'jupyterlab' 'jupyterhub' && \
2024-04-11 22:09:41 +08:00
pip install jupyterlab-language-pack-zh-CN jupyterlab_tabnine && \
pip cache purge
WORKDIR "${HOME}"
# Configure container startup
ENTRYPOINT ["tini", "-g", "--", "start.sh"]
CMD ["start-notebook.py"]