Custom Jupyter Image¶
Create, publish, and use your own Docker image for Kubeflow.
-
Custom packages
Customize environment to your needs.
-
Reproducibility
Same environment for the entire team.
-
Teaching
Pre-prepared images for courses.
-
Research
Specific ML libraries and tools.
Dockerfile¶
Base image¶
# NOTE: Use Makefile or buildx for proper build steps.
ARG BASE_IMG=ghcr.io/kubeflow/kubeflow/notebook-servers/jupyter-pytorch:latest
FROM ${BASE_IMG}
USER root
ENV DEBIAN_FRONTEND=noninteractive
# 1) System tools and libraries
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
sudo git curl wget vim nano htop unzip \
build-essential cmake pkg-config \
libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev \
libjpeg-dev libpng-dev libtiff-dev \
libblas-dev liblapack-dev gfortran python3-dev \
libgl1 libglib2.0-0 ffmpeg graphviz \
&& rm -rf /var/lib/apt/lists/*
# 2) Passwordless sudo for NB_USER
RUN usermod -aG sudo "${NB_USER}" \
&& echo "${NB_USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-nbuser \
&& chmod 0440 /etc/sudoers.d/99-nbuser
# 3) Basic mamba/conda packages
RUN mamba install -y -q --freeze-installed \
numpy scipy pandas scikit-learn scikit-image seaborn \
sympy statsmodels networkx \
&& mamba clean -a -f -y
# 4) Pip packages (ML/DL)
ENV PIP_NO_CACHE_DIR=1
ENV MPLBACKEND=Agg
RUN python -m pip install -U pip setuptools wheel \
&& python -m pip install \
matplotlib ipympl bokeh plotly \
opencv-python-headless \
xgboost lightgbm \
nltk spacy \
transformers datasets \
pytorch-lightning
# 5) Custom requirements
COPY --chown=${NB_USER}:${NB_GID} requirements.txt /tmp/requirements.txt
RUN python -m pip install -r /tmp/requirements.txt \
&& rm -f /tmp/requirements.txt
# 6) Back to NB_USER
USER ${NB_USER}
requirements.txt¶
Build and Push¶
Makefile¶
IMAGE ?= repository.cloud.tuke.sk/ml/jupyter-pytorch-plus
TAG ?= v1.0.0
.PHONY: build push
build:
docker build -t $(IMAGE):$(TAG) .
push:
docker push $(IMAGE):$(TAG)
Commands¶
# Build
make build IMAGE=repository.cloud.tuke.sk/ml/jupyter-pytorch-plus TAG=v1.0.0
# Login to registry
docker login repository.cloud.tuke.sk
# Push
make push IMAGE=repository.cloud.tuke.sk/ml/jupyter-pytorch-plus TAG=v1.0.0
Usage in Kubeflow¶
Create new notebook¶
In Kubeflow UI, go to Notebooks → New Notebook.
Enter Custom Image¶
In the Custom Image field, enter:
Set resources and launch¶
Set CPU, RAM, and Workspace Volume, then click Launch.
What the Image Contains¶
System libraries (APT)¶
| Package | Purpose |
|---|---|
| build-essential, cmake | Python package compilation |
| libjpeg, libpng, libtiff | Image processing |
| ffmpeg | Audio/video, OpenCV |
| graphviz | Graphs, DAG visualizations |
Conda/Mamba packages¶
| Package | Purpose |
|---|---|
| numpy, scipy, pandas | Numerical computing |
| scikit-learn, scikit-image | Machine learning |
| seaborn, sympy, statsmodels | Visualization, statistics |
| networkx | Graph algorithms |
Pip packages (ML/DL)¶
| Package | Purpose |
|---|---|
| matplotlib, bokeh, plotly | Visualization |
| opencv-python-headless | Computer vision |
| xgboost, lightgbm | Gradient boosting |
| nltk, spacy | NLP |
| transformers, datasets | Hugging Face ecosystem |
| pytorch-lightning | PyTorch wrapper |
Practical Recommendations¶
Best practices
- Pin versions – especially PyTorch, CUDA, HF transformers
- Don't download models in build phase – they increase image size
- Use CHANGELOG and versions like
v1.0.0 - Don't use
:latestin production - Put frequently changing things lower in Dockerfile
Post-deploy Check¶
python -c "import torch, transformers, sklearn, cv2; \
print('Torch:', torch.__version__); \
print('Transformers:', transformers.__version__); \
print('cv2:', cv2.__version__)"
python -c "import kfp; print('KFP:', kfp.__version__)"
jupyter labextension list
Code-server Image (VS Code)¶
For VS Code in browser, create a similar image with code-server:
IMAGE ?= repository.cloud.tuke.sk/dev/codeserver
TAG ?= v1.0.0
build:
docker build -t $(IMAGE):$(TAG) .
push:
docker push $(IMAGE):$(TAG)
Local test¶
docker run --rm -p 8888:8888 \
-e PASSWORD='strong-password' \
repository.cloud.tuke.sk/dev/codeserver:v1.0.0 \
code-server --bind-addr 0.0.0.0:8888 --auth password /home/jovyan