Anish Pillay
Anish Pillay

Reputation: 1

How to launch jupyter notebook in gcloud compute engine

I would like to use jupyter notebook from google cloud compute engine. When i try to launch it through command line, I am not able to open the notebook using my browser.

Please let me know on how to do this.

Upvotes: 0

Views: 1072

Answers (2)

Hu Xixi
Hu Xixi

Reputation: 2147

You can also "Create Firewall Rules" to allow your jupyter c.NotebookApp.port number.
refer this image set Protocols and ports to tcp:<jupyter port number>

Upvotes: 0

Tuxdude
Tuxdude

Reputation: 49473

It looks like you're trying to start a Jupyter notebook server on the VM and want to access it using the external IP of the VM (assuming you have not disabled the external IP option on your VM).

You will need to do the following:

  1. Modify jupyter_notebook_config.py in your ~/.jupyter directory. Do go through exactly what you need to modify and how to secure your notebook server since Jupyter notebook by default only listens on the loopback interface (i.e. 127.0.0.1 aka localhost).

The minimum set of configuration options that you should uncomment and edit in jupyter_notebook_config.py is the following:

# Set options for certfile, ip, password, and toggle off
# browser auto-opening
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999
  1. You will need to modify the firewall rules to allow ingress traffic to the port (on the VM) you just configured in the previous step. To do that I will recommend tag based firewall rules so that you can control which VMs the firewall rule applies to.

Network tags are used by networks to identify which instances are subject to certain firewall rules and network routes. For example, if you have several VM instances that are serving a large website, tag these instances with a shared word or term and then use that tag to apply a firewall rule that allows HTTP access to those instances. Tags are also reflected in the metadata server, so you can use them for applications running on your instances. When you create a firewall rule, you can provide either sourceRanges or sourceTags but not both.

# Assuming Jupyter notebook is running on port 9999
# Add a new tag based firewall rule to allow ingress tcp:9999
gcloud compute firewall-rules create rule-allow-tcp-9999 --source-ranges 0.0.0.0/0 --target-tags allow-tcp-9999 --allow tcp:9999

# Add the allow-tcp-9999 target tag to the VM named say 'vm-1'
gcloud compute instances add-tags vm-1 --tags allow-tcp-9999

# If you want to list all the GCE firewall rules
gcloud compute firewall-rules list

It might take a few seconds to couple of minutes for the changes to take effect.

Alternatively, you can also use Google Cloud Console instead of gcloud to configure firewall rules. You can go through this answer which explains that in detail.

Upvotes: 1

Related Questions