Search code examples
google-cloud-platformgoogle-compute-enginegoogle-cloud-mlgcp-ai-platform-notebook

Requirements for launching Google Cloud AI Platform Notebooks with custom docker image


On AI Platform Notebooks, the UI lets you select a custom image to launch. If you do so, you're greeted with an info box saying that the container "must follow certain technical requirements":

certain technical requirements

I assume this means they have a required entrypoint, exposed port, jupyterlab launch command, or something, but I can't find any documentation of what the requirements actually are.

I've been trying to reverse engineer it without much luck. I nmaped a standard instance and saw that it had port 8080 open, but setting my image's CMD to run Jupyter Lab on 0.0.0.0:8080 did not do the trick. When I click "Open JupyterLab" in the UI, I get a 504.

Does anyone have a link to the relevant docs, or experience with doing this in the past?


Solution

  • There are two ways you can create custom containers:

    Building a Derivative Container

    If you only need to install additional packages, ou should create a Dockerfile derived from one of the standard images (for example, FROM gcr.io/deeplearning-platform-release/tf-gpu.1-13:latest), then add RUN commands to install packages using conda/pip/jupyter.

    The conda base environment has already been added to the path, so no need to conda init/conda activate unless you need to setup another environment. Additional scripts/dynamic environment variables that need to be run prior to bringing up the environment can be added to /env.sh, which is sourced as part of the entrypoint.

    For example, let’s say that you have a custom built TensorFlow wheel that you’d like to use in place of the built-in TensorFlow binary. If you need no additional dependencies, your Dockerfile will be similar to:

    Dockerfile.example

    FROM gcr.io/deeplearning-platform-release/tf-gpu:latest
    RUN pip uninstall -y tensorflow-gpu && \
        pip install -y /path/to/local/tensorflow.whl
    

    Then you’ll need to build and push it somewhere accessible to your GCE service account.

    PROJECT="my-gcp-project"
    docker build . -f Dockerfile.example -t "gcr.io/${PROJECT}/tf-custom:latest"
    gcloud auth configure-docker
    docker push "gcr.io/${PROJECT}/tf-custom:latest"
    

    Building Container From Scratch

    The main requirement is that the container must expose a service on port 8080.

    The sidecar proxy agent that executes on the VM will ferry requests to this port only.

    If using Jupyter, you should also make sure your jupyter_notebook_config.py is configured as such:

    c.NotebookApp.token = ''
    c.NotebookApp.password = ''
    c.NotebookApp.open_browser = False
    c.NotebookApp.port = 8080
    c.NotebookApp.allow_origin_pat = (
    '(^https://8080-dot-[0-9]+-dot-devshell\.appspot\.com$)|'
    '(^https://colab\.research\.google\.com$)|'
    '((https?://)?[0-9a-z]+-dot-datalab-vm[\-0-9a-z]*.googleusercontent.com)')
    c.NotebookApp.allow_remote_access = True
    c.NotebookApp.disable_check_xsrf = False
    c.NotebookApp.notebook_dir = '/home'
    

    This disables notebook token-based auth (auth is instead handled through oauth login on the proxy), and allows cross origin requests from three sources: Cloud Shell web preview, colab (see this blog post), and the Cloud Notebooks service proxy. Only the third is required for the notebook service; the first two support alternate access patterns.