Skip to content

Instantly share code, notes, and snippets.

@leonmak
Last active November 16, 2017 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonmak/4608e85ac2253aa781dace7a54fd1633 to your computer and use it in GitHub Desktop.
Save leonmak/4608e85ac2253aa781dace7a54fd1633 to your computer and use it in GitHub Desktop.
Setup jupyter notebook

Notes on setting up Jupyter notebook on instances

Configuring instance

For gcloud:

  • Specified protocols and ports > Enter tcp:<PORT-NUMBER> for this field if this is the page you see.
  • Targets > All instances in the network.
  • Allowed protocols and ports

For others:

  • Specify ip port if you want to expose one
  • If not, just put public IP

SSH Keys from A to B

a@A:~> ssh-keygen -t rsa
a@A:~> ssh b@B mkdir -p .ssh
a@A:~> cat .ssh/your_key_name.pub | ssh b@B 'cat >> .ssh/authorized_keys'
a@A:~> ssh b@B

Edit password:

sudo su
passwd your_username

Jupyter

Move files to instance

gtar --exclude="*.h5" -cvzf  your-directory.tgz your-directory
scp -i ~/.ssh/your_key_name your-directory.tgz username@99.11.000.252:/home/username/
ssh username@99.11.000.252 -i ~/.ssh/your_key_name

Configure jupyter notebook

Setting up cuda

We'll be using the easy way

wget -O - -q 'https://gist.githubusercontent.com/dte/8954e405590a360614dcc6acdb7baa74/raw/d1b5a01ed0b9252654016d2a9a435dc8b4c045e7/install-CUDA-docker-nvidia-docker.sh' | sudo bash  
sudo shutdown -r now  
sudo nvidia-docker run --rm --name your-notebook-name -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow:latest-gpu jupyter notebook --allow-root 

Note: we use the name but if you want to use id docker ps to see the id

Transfer files to docker container

sudo docker cp your-directory.tgz your-notebook-name:/notebooks

Attach to the docker container

docker exec -it your-notebook-name /bin/bash
tar -xzvf your-directory.tgz

Prerequisites: setting up virtualenv

apt-get update
apt-get upgrade -y

apt-get install wget
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip3 install virtualenv virtualenvwrapper

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

source ~/.bashrc

mkvirtualenv your-venv-name
workon your-venv-name
python -m ipykernel install --user --name myenv --display-name "your-display-name"

Configuring jupyter notebook

ls ~/.jupyter/jupyter_notebook_config.py
jupyter notebook --generate-config
nano ~/.jupyter/jupyter_notebook_config.py

Edit and replace

c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = <PORT-NUMBER>
jupyter-notebook --no-browser --port=<PORT-NUMBER> 

Saving state

You want to do this to save what we've done so far.

sudo docker ps
sudo docker commit your-notebook-name leonmak/ubuntu-cuda

# Create your repo on hub.docker.com
sudo docker login # if you haven't
sudo docker images
sudo docker push leonmak/ubuntu-cuda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment