How to run Cloud Datalab on your laptop

Cloud Datalab is the hosted way to run Jupyter notebooks on Google Cloud. But if you run a lot of managed services (Cloud ML Engine, Dataflow, BigQuery, etc.), you don’t really need a powerful VM — your laptop is enough. At the same time, it can be helpful to have a git repository on your local laptop, develop Python files in PyCharm, and still use Datalab for its GCP integration.

Can you run Datalab on your laptop?

This is how you can run Datalab even when you are not connected to the Cloud

Yes. This is what I do (note: this is completely unofficial and unsupported):

  1. Install Docker on your laptop.
  2. Install the gcloud SDK on your laptop
  3. In a terminal, run ```gcloud auth login``` to login to your project
  4. In the same terminal, save and run run this script (change the CONTENT) variable first!
#!/bin/bash
IMAGE=gcr.io/cloud-datalab/datalab:latest
CONTENT=${HOME}/code/training-data-analyst # your git repo
PROJECT_ID=$(gcloud config get-value project)
if [ "$OSTYPE" == "linux"* ]; then
PORTMAP="127.0.0.1:8081:8080"
else
PORTMAP="8081:8080"
fi

docker pull $IMAGE
docker run -it \
-p $PORTMAP \
-v "$CONTENT:/content" \
-e "PROJECT_ID=$PROJECT_ID" \
$IMAGE

Now, you can simply browse to http://localhost:8080/ and from there open any notebook in your local repo, and work on it using Datalab.