3

I'm using the instructions to start the Deep Learning Image from Cloud Shell:

export IMAGE_FAMILY="tf-latest-cu92"
export ZONE="us-central1-f"
export INSTANCE_NAME="myvm"

gcloud compute instances create $INSTANCE_NAME \
   --zone=$ZONE  \
  --image-family=$IMAGE_FAMILY  \
  --image-project=deeplearning-platform-release  \
  --maintenance-policy=TERMINATE  \
  --accelerator='type=nvidia-tesla-v100,count=1' \
   --metadata='install-nvidia-driver=True'

The VM starts and I can ssh to it and see that Jupyter Lab is running.

However, I can not do a WebPreview from Cloud Shell to connect to it. What am I doing wrong?

Lak
  • 3,876
  • 20
  • 34

2 Answers2

3

Unfortunately, WebPreview from CloudShell to JupyterLab on the deep learning image doesn't currently work. The team is working on this.

Until then, please install and use gcloud ssh from your laptop (note the -- between instance name and -L):

export INSTANCE_NAME="myvm"
gcloud compute ssh $INSTANCE_NAME -- -L 8080:localhost:8080
Lak
  • 3,876
  • 20
  • 34
2

The reason you cannot use Cloud Shell web preview to connect to JupyterLab is that web preview connects to your Cloud Shell VM instance, while JupyterLab is running on myvm (a separate instance) that you created with gcloud compute instances create

However, you can use ssh tunneling within Cloud Shell, much like you propose in your own answer and then use Cloud Shell web preview.

For instance, I am able to successfully connect to JupyterLab using web preview if I execute the following within Cloud Shell after setting up the environment variables and creating the instance:

export IMAGE_FAMILY="tf-latest-cu92"
export ZONE="us-central1-f"
export INSTANCE_NAME="myvm"

gcloud compute instances create ...

gcloud compute ssh $INSTANCE_NAME --zone=$ZONE  -- -L 8080:localhost:8080

UPDATE: As pointed out in the comments, the above is not sufficient to get JupyterLab (as configured in the Deep Learning Image) to work with Cloud Shell; we also need to configure JupyterLab to allow cross-origin requests. Since we are tunneling through ssh, it's also a good practice to restrict JupyterLab connections to localhost (for security reasons). To achieve this, run the following commands on myvm (e.g., after setting up the tunnel above):

myvm$ sudo sed -i \
               -e "s/\(c.NotebookApp.ip\).*/\1 = 'localhost'/g; \
                   s/\(c.NotebookApp.allow_origin\).*/\1 = '*'/g" \
               /root/.jupyter/jupyter_notebook_config.py
myvm$ sudo pkill jupyter-lab # restart to pick up config
MaratB
  • 649
  • 3
  • 8
  • FWIW, I can connect to the Jupyter Lab interface that way, but actually doing anything -- like creating a notebook -- results in many 404 errors. I haven't tested on a system that has a native shell, only on Chromebook. – ToddR Aug 07 '18 at 19:32
  • 1
    This does not work for Jupyter Lab, looks like proxy that is used with Cloud Shell somehow not fully compatible with the Jupyter Lab :( even though you can connect and see initial Jupyter Lab screen(this might lead to the assumption that it actually work), but any attempt to create the new notebook will result in 404. – Viacheslav V Kovalevskyi Sep 04 '18 at 18:13
  • 1
    @ToddR thanks for noticing, clearly I didn't test Jupyter Lab deeply enough. I updated the answer with additional instructions on tweaking JupyterLab config to make it work. – MaratB Sep 13 '18 at 00:59
  • @ViacheslavVKovalevskyi, I updated the answer with additional instructions on modifying JupyterLab config. – MaratB Sep 13 '18 at 00:59