Last active
November 16, 2025 14:11
-
-
Save SomeBottle/8a75d490d2616ecfe100e676564ac769 to your computer and use it in GitHub Desktop.
My JupyterLab Docker Container for Research Experiments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Author
Packages planned to install: timm, einops
Author
2025.10.22:
- Change the base image from
bitnami/pythonto officialpython. - Use USTC pypi mirror due to rate-limiting of tsinghua mirror.
- Add packages
timm,einops.
Author
Startup command example:
# If shm-size is not specified, it may easily get out of shared memory when loading data batch for training, docker only allocates 64 MiB by default.
docker run --gpus all -d --restart=unless-stopped --shm-size=16g --env JUPYTER_PASSWORD='<Password used on WebUI>' \
--env JUPYTER_TOKEN='<Token for remote connections>' \
-v <Your notebook workdir>:/app \
-p 9527:9527 -p 9528:6006 --name=somebottle-jupyter somebottle/jupyter-torch:0.0.7- Tensorboard default port inside container:
6006, here I map it to host port9528. - Tensorboard won't start by default, please use
screen -dmS tb tensorboard --host=0.0.0.0 --logdir=<Log dir>to run it in the background.
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
Dockerhub repository: https://hub.docker.com/r/somebottle/jupyter-torch