Connect Google colab to a runtime on a Google Compute Engine instance

Viewed 4714

I am trying to connect a jupyter notebook on Google colab to a runtime on GCP EC2 instance. I followed this colab doc instructions Link

Steps taken:

  • Set up a Jupyter server on my local

    pip install jupyter_http_over_ws && jupyter serverextension enable --py jupyter_http_over_ws
    
    jupyter notebook \
     --NotebookApp.allow_origin='https://colab.research.google.com' \
     --port=8888 \
     --NotebookApp.port_retries=0
    
  • Create and start a EC2 instance on GCP

  • SSH into EC2 instance and forward local port using:

    gcloud beta compute ssh --zone "europe-west2-c" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
    

Error Message from trying to forward the port:

bind [127.0.0.1]:8888: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8888
Could not request local forwarding.

I also tried connecting the ec2 instance directly to colab but I was unable to. For the final step, I am suppose to copy the Jupyter url to the colab local runtime. How can I fix this?

1 Answers

I figured it out.

Steps:

  • Start instance

  • Connect to instance and forward port on remote instance to local machine

    gcloud beta compute ssh --zone "<zone>" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
    
  • Install jupyter notebook and jupyter_http_over_ws if you dont have it install on the remote instance already.

  • Then enable jupyter_http_over_ws:

    jupyter serverextension enable --py jupyter_http_over_ws
    
  • Start Jupyter server on remote instance

    jupyter notebook \
     --NotebookApp.allow_origin='https://colab.research.google.com' \
     --port=8888 \
     --NotebookApp.port_retries=0
    
  • Copy server url to colab

Related