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:
  1. --notebook-dir=/home/jovyan

The /home/jovyan directory is backed by aKubernetes persistent volume (PV).

  • Allow Jupyter to listen on all IP addresses:
  1. --ip=0.0.0.0
  • Allow the user to run the notebook as root:
  1. --allow-root
  • Set the port:
  1. --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:

  1. --NotebookApp.token='' --NotebookApp.password=''
  • Allow any origin to access your Jupyter notebook server:
  1. --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 of base_url asfollows:
  1. --NotebookApp.base_url=NB_PREFIX

Below is an example of what your Dockerfile should contain:

  1. ENV NB_PREFIX /
  2. 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.

Feedback

Was this page helpful?

Glad to hear it! Please tell us how we can improve.

Sorry to hear that. Please tell us how we can improve.

Last modified 19.04.2019: Refactored and significantly updated the Jupyter notebooks docs (#633) (4e1d8ab2)