-
-
Save SomeBottle/8a75d490d2616ecfe100e676564ac769 to your computer and use it in GitHub Desktop.
| # 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 && \ | |
| echo 'export PATH=$PATH:'$NVM_DIR/versions/node/v24.*/bin >> /etc/profile.d/node.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 && \ | |
| pip install --no-cache-dir nvidia-ml-py grad-cam rich seaborn scipy && \ | |
| pip install --no-cache-dir transformers peft accelerate safetensors bitsandbytes trl | |
| 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 && \ | |
| echo 'c.ServerApp.allow_root = True' >> $JUPYTER_CONF_DIR/jupyter_server_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 libgl1 acl && \ | |
| apt-get clean && \ | |
| rm -rf /var/lib/apt/lists/* | |
| USER somebottle | |
| ENV NVM_DIR=/home/somebottle/.nvm | |
| RUN mkdir -p "$NVM_DIR" && \ | |
| curl -o- https://fastly.jsdelivr.net/gh/nvm-sh/nvm@v0.40.8/install.sh | bash && \ | |
| . "$NVM_DIR/nvm.sh" && \ | |
| nvm install 24 && \ | |
| nvm alias default 24 | |
| # 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 |
2025.7.2: Add tensorboard, tensorboardX libraries.
According to the document: https://jupyter-server.readthedocs.io/en/latest/api/jupyter_server.auth.html#jupyter_server.auth.identity.IdentityProvider.token
We can configure a token as an alternative authentication method by using -e JUPYTER_TOKEN=xxx when running this docker image.
This is especially useful when you are using jupyter extension in VSCode.
Dockerhub repository: https://hub.docker.com/r/somebottle/jupyter-torch
Packages planned to install: timm, einops
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.
Build command example:
docker build --build-arg HTTP_PROXY="http://127.0.0.1:7890" --build-arg HTTPS_PROXY="http://127.0.0.1:7890" --build-arg NO_PROXY="localhost,127.0.0.1,.example.com" --network=host -t somebottle/jupyter-torch:0.1.0 .Startup command example:
# If shm-size is not specified, it may easily run out of shared memory when loading data batches with multiple workers. 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.
Planned new package:
- pyNVML - used to retrieve detailed GPU status info.
- pytorch-grad-cam
- rich
- seaborn
- scipy
2025.12.2:
- Add python packages:
nvidia-ml-pygrad-camrichseabornscipy
- Add Debian package:
libgl1
2026.10.26:
-
Add python packages:
transformerspeftacceleratesafetensorsbitsandbytestrl
-
Add nvm and install node v24 by default.
Warning
For BackWeak implementation, please use somebottle/jupyter-torch:0.0.8 or somebottle/jupyter-torch:0.0.7.
2026.10.28:
-
Add Debian package:
acl
-
Add new script
share_acl.shto solve permission issues.
share_acl script usage
Place this script in the /media/notebook_workdir directory. Assume that when I start the container, I want to mount the host's /media/notebook_workdir to the /app path inside the container.
First, run the following command in the host directory:
cd /media/notebook_workdir
chmod +x share_acl.sh
./share_acl.sh host /media/notebook_workdir 100999Here, 100999 is the UID on the host that corresponds to the user inside the container, the exact value depends on whether Docker is running in rootless or rootful mode.
Note
You can first create a file in that directory inside the container, then check the UID that owns the file on the host.
Then enter the container and run the following command inside the container:
/app/share_acl.sh container /appIn this way, file permission issues can be resolved to some extent.
2025.6.11: Add
kornialibrary.