Create a Custom Jupyter Image
Creating a custom Docker image for your Jupyter notebook
This guide tells you how to configure a custom Docker image for your Jupyternotebook server in Kubeflow.
Your custom image must meet the requirements of the Kubeflow notebookcontroller which manages the life cycle of notebooks. The Kubeflow UI expectsJupyter to start after launching the Docker image with docker run
. You musttherefore set the default command of your Docker image to launch Jupyter.
Follow these steps to configure the launch command (CMD
) in your Docker image:
- Set the working directory:
--notebook-dir=/home/jovyan
The /home/jovyan
directory is backed by aKubernetes persistent volume (PV).
- Allow Jupyter to listen on all IP addresses:
--ip=0.0.0.0
- Allow the user to run the notebook as root:
--allow-root
- Set the port:
--port=8888
- Disable authentication. (Kubeflow takes care of authentication based onthe type of authentication selected during deployment of Kubeflow. Afterauthentication to Kubeflow, users can access all Kubeflow componentsfrom the UI, including notebooks.)
Use the following setting to allow passwordless access to your Jupyternotebook servers:
--NotebookApp.token='' --NotebookApp.password=''
- Allow any origin to access your Jupyter notebook server:
--NotebookApp.allow_origin='*'
- Set the base URL. The Kubeflow notebook controller manages the base URL forthe notebook server using the environment variable called
NB_PREFIX
. YourDocker image should define the variable and set the value ofbase_url
asfollows:
--NotebookApp.base_url=NB_PREFIX
Below is an example of what your Dockerfile should contain:
ENV NB_PREFIX /
CMD ["sh","-c", "jupyter notebook --notebook-dir=/home/jovyan --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]
Next steps
When starting a Jupyter notebook server from theKubeflow UI, specify your custom Docker image. See the guide to setting upyour Jupyter notebooks.