Running Jupyter Notebook on Google Cloud Platform in 15 min | by Amulya Aankul | Towards Data Science

Recently, while I was doing my research project on Computer Vision using Convolutional Neural Network, I found out that my 8GB RAM laptop is useless. It took me an hour to learn from just 1 epoch. Therefore, rather than spending 1500$ on a new GPU based laptop, I did it for free on Google Cloud. (Google Cloud gives 300$ credit, and I have 3 gmail accounts and 3 credit cards :D)
So lets not waste anymore time and move straight to running jupyter notebook in GCP.
For this step, you will have to put your payment information and verify your account. It’s the most simple step. If you fail this step, close your laptop and think where you are going in life.
Click on the three dots shown in the image below and then click on the + sign to create a new project.
Click on the three lines on the upper left corner, then on the compute option, click on ‘Compute Engine’
Now click on ‘Create new instance’. Name your instance, select zone as ‘ us-west1-b’. Choose your ‘machine type’. (I chose 8v CPUs).
Select your boot disk as ‘Ubuntu 16.04 LTS’. Under the firewall options tick both ‘http’ and ‘https’ (very important). Then, choose the disk tab and untick ‘ Delete boot disk when instance is deleted’.
If you click on ‘customize’, you will be able to find options for using GPUs. You can choose between 2 NVIDIA GPUs.
Some firewall settings:-
Now click on ‘Create’ and your instance is ready!
Your new VM instance should look something like this. Note down the External IP.
IMPORTANT : DON’T FORGET TO STOP YOUR GPU INSTANCE AFTER YOU ARE DONE BY CLICKING ON THE THREE DOTS ON THE IMAGE ABOVE AND SELECTING STOP. OTHERWISE GCP WILL KEEP CHARGING YOU ON AN HOURLY BASIS.
By default, the external IP address is dynamic and we need to make it static to make our life easier. Click on the three horizontal lines on top left and then under networking, click on VPC network and then External IP addresses.
Change the type from Ephemeral to Static.
Now, click on the ‘Firewall rules’ setting under Networking.
Click on ‘Create Firewall Rules’ and refer the below image:
Under protocols and ports you can choose any port. I have chosen tcp:5000 as my port number. Now click on the save button.
Now start your VM instance. When you see the green tick click on SSH. This will open a command window and now you are inside the VM.
In your SSH terminal, enter:
wget http://repo.continuum.io/archive/Anaconda3-4.0.0-Linux-x86_64.shbash Anaconda3-4.0.0-Linux-x86_64.sh
and follow the on-screen instructions. The defaults usually work fine, but answer yes to the last question about prepending the install location to PATH:
Do you wish the installer to prepend the Anaconda3 install location to PATH in your /home/haroldsoh/.bashrc ? [yes|no][no] >>> yes
To make use of Anaconda right away, source your bashrc:
source ~/.bashrc
Now, install other softwares :
pip install tensorflowpip install keras
Open up a SSH session to your VM. Check if you have a Jupyter configuration file:
ls ~/.jupyter/jupyter_notebook_config.py
If it doesn’t exist, create one:
jupyter notebook --generate-config
We’re going to add a few lines to your Jupyter configuration file; the file is plain text so, you can do this via your favorite editor (e.g., vim, emacs). Make sure you replace the port number with the one you allowed firewall access to in step 5.
c = get_config()c.NotebookApp.ip = '*'c.NotebookApp.open_browser = Falsec.NotebookApp.port = <Port Number>
It should look something like this :
To run the jupyter notebook, just type the following command in the ssh window you are in :
jupyter-notebook --no-browser --port=<PORT-NUMBER>
Once you run the command, it should show something like this:
Now to launch your jupyter notebook, just type the following in your browser:
http://<External Static IP Address>:<Port Number>
where, external ip address is the ip address which we made static and port number is the one which we allowed firewall access to.
Congratulations! You successfully installed jupyter notebook on GCP!
Lets connect : https://www.linkedin.com/in/aankul
Follow me on medium: https://medium.com/@aankul.a
Edit :All those facing ‘ERR_CONNECTION_TIMED_OUT’ error. Please try Bastardized Eloquence’s solution in the comments.
Some rights reserved