Skip to content

Instantly share code, notes, and snippets.

@SomeBottle
Last active November 16, 2025 14:11
Show Gist options
  • Select an option

  • Save SomeBottle/8a75d490d2616ecfe100e676564ac769 to your computer and use it in GitHub Desktop.

Select an option

Save SomeBottle/8a75d490d2616ecfe100e676564ac769 to your computer and use it in GitHub Desktop.
My JupyterLab Docker Container for Research Experiments
# FROM python:3.11.14-bookworm
FROM docker.1ms.run/python:3.11.14-bookworm
# 【可配置环境变量】
# JUPYTER_PASSWORD: Jupyter 登录密码,不配置的话默认是随机字串
# JUPYTER_WORKDIR: 工作目录,默认是 /app
# JUPYTER_PORT: Jupyter 端口,默认是 9527
ENV JUPYTER_WORKDIR="/app" \
JUPYTER_CONF_DIR="/home/somebottle/.jupyter" \
JUPYTER_PORT=9527 \
PIP_INSTALL_BIN_DIR="/home/somebottle/.local/bin" \
PYTHON_BIN_DIR="/usr/local/bin"
USER root
WORKDIR $JUPYTER_WORKDIR
RUN useradd -m -s /bin/bash -U somebottle && \
echo 'export PATH=$PATH:'$PIP_INSTALL_BIN_DIR > /etc/profile.d/jupyter.sh && \
echo 'export PATH=$PATH:'$PYTHON_BIN_DIR >> /etc/profile.d/python.sh && \
chown -R somebottle:somebottle $JUPYTER_WORKDIR
USER somebottle
RUN pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simple && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir torch torchvision torchaudio matplotlib scikit-learn pillow tqdm pandas opencv-python kornia crc32c soundfile tensorboard tensorboardX imagehash && \
pip install --no-cache-dir timm einops
RUN bash -c "source /etc/profile && \
pip install --no-cache-dir jupyter notebook jupyterlab && \
pip install --no-cache-dir jupyterlab-language-pack-zh-CN && \
jupyter notebook --generate-config && \
echo 'c.ServerApp.password_required = True' >>$JUPYTER_CONF_DIR/jupyter_notebook_config.py"
USER root
RUN echo "deb http://deb.debian.org/debian bookworm main contrib non-free" | tee /etc/apt/sources.list && \
echo "deb http://deb.debian.org/debian-security bookworm-security main contrib non-free" | tee -a /etc/apt/sources.list && \
echo "deb http://deb.debian.org/debian bookworm-updates main contrib non-free" | tee -a /etc/apt/sources.list && \
sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y vim zip screen nano tree lsof htop ncurses-bin binutils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
USER somebottle
# entrypoint
COPY entrypoint.sh /home/somebottle/entrypoint.sh
ENTRYPOINT ["/bin/bash", "/home/somebottle/entrypoint.sh"]
#!/bin/bash
export SHELL=/bin/bash
if [ -z $JUPYTER_PASSWORD ]; then
export JUPYTER_PASSWORD=$(openssl rand -hex 32)
fi
HASHED_PASSWD=$(python -c "from jupyter_server.auth import passwd;print(passwd('$JUPYTER_PASSWORD', algorithm='sha256'))")
if [ ! -f $JUPYTER_CONF_DIR/init.flag ]; then
echo "c.ServerApp.password = '$HASHED_PASSWD'" >> $JUPYTER_CONF_DIR/jupyter_notebook_config.py
echo "c.ServerApp.terminado_settings = {'shell_command': ['/bin/bash']}" >> $JUPYTER_CONF_DIR/jupyter_notebook_config.py
touch $JUPYTER_CONF_DIR/init.flag
fi
source /etc/profile
jupyter lab --ip=0.0.0.0 --port $JUPYTER_PORT --no-browser --notebook-dir=$JUPYTER_WORKDIR
@SomeBottle
Copy link
Author

Planned new package:

  • pyNVML - used to retrieve detailed GPU status info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment