jupyter/python/Dockerfile

63 lines
2.5 KiB
Docker
Raw Normal View History

2025-01-19 23:05:27 +08:00
FROM debian:trixie-slim
ARG PYPI_MIRROR
ARG DEBIAN_MIRROR
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/${DEBIAN_MIRROR}/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/* && \
2024-10-26 06:08:52 +08:00
# enhance scripts & repair HEALTHCHECK permission denied
chmod a+rx /usr/local/bin/* /etc/jupyter/docker_healthcheck.py && \
# 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" && \
echo "[global]\nindex-url = ${PYPI_MIRROR}" > /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-11-02 17:30:30 +08:00
# install jupyterlab jupyterhub extension python-lsp
2024-04-12 16:10:40 +08:00
RUN pip install 'jupyterlab' 'jupyterhub' && \
2024-11-02 17:30:30 +08:00
pip install jupyterlab-language-pack-zh-CN jupyterlab-lsp jupyterlab-execute-time jedi-language-server && \
2024-04-11 22:09:41 +08:00
pip cache purge
WORKDIR "${HOME}"
# Configure container startup
ENTRYPOINT ["tini", "-g", "--", "start.sh"]
CMD ["start-notebook.py"]