[PYTHON] Try building JupyterHub with Docker

Before

At PyCon 2015, iPython (Jupyter) Notebook is indispensable for various people! So I thought I'd install it for the time being, but I didn't have enough Japanese information that I tried Jupyter Saba with Docker, so I'll share the work record.

install docker

Since Debian 8 (Jassie) is the mother ship,

$ sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

bash:/etc/apt/sources.list.d/docker.list


# Debian Jessie
deb https://apt.dockerproject.org/repo debian-jessie main
$ sudo apt-get update
$ sudo apt-get install docker-engine
$ sudo usermod -a -G docker yi01

Creating a Docker image for JupyterHub

There are some traps here.

First, it's on Docker Hub

There is no implementation around authentication, so you need to create jupyterhub_config.py and define the authentication method etc. using the -v option of docker.

However, it is troublesome to make various things from scratch, so I will use example using OAuth on GitHub prepared by jupyter.

$ git clone https://github.com/jupyter/oauthenticator.git
$ cd oauthenticator

Now, edit the userlist according to the README.

GitHub user settings


diff --git a/example/addusers.sh b/example/addusers.sh
index eb2d86b..cedd272 100644
--- a/example/addusers.sh
+++ b/example/addusers.sh
@@ -7,6 +7,6 @@ for line in `cat userlist`; do
   user=`echo $line | cut -f 1 -d' '`
   echo "adding user $user"
   useradd -m -s /bin/bash $user
-  cp -r /srv/ipython/examples /home/$user/examples
-  chown -R $user /home/$user/examples
+#  cp -r /srv/ipython/examples /home/$user/examples
+#  chown -R $user /home/$user/examples
 done
diff --git a/example/userlist b/example/userlist
index e69de29..d8f3556 100644
--- a/example/userlist
+++ b/example/userlist
@@ -0,0 +1 @@
+YusukeIwaki admin

As a caveat, if you just edit the userlist, with docker build

cp: cannot stat ‘/srv/ipython/examples’: No such file or directory
chown: cannot access ‘/home/YusukeIwaki/examples’: No such file or directory

I get an error like this and it gets moss, so I will edit the shell script a little. After editing,

$ cd example
$ docker build -t jupyter/oauthenticator .

So, if you get a Succeed-like log,

Verification


$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jupyter/oauthenticator   latest              209358b449b6        24 seconds ago      934.9 MB
jupyter/jupyterhub       latest              fd5445f17a96        5 days ago          934.8 MB

GitHub OAuth settings

At GitHub Settings Screen スクリーンショット 2015-10-12 1.14.29.png

Set like this. Please read the callback host name and port number as appropriate. After registering the OAuth authentication information on the GitHub site side, enter the Client ID and secret obtained there.

secret


diff --git a/example/env b/example/env
index 9f32b5c..7a921da 100644
--- a/example/env
+++ b/example/env
@@ -1,5 +1,5 @@
 # add your github oauth config to this file,
 # and run the container with `docker run -it -p 9000:8000 --env-file=env jupyter/oauthenticator`
-GITHUB_CLIENT_ID=
-GITHUB_CLIENT_SECRET=
-OAUTH_CALLBACK_URL=
+GITHUB_CLIENT_ID=21d***********e7a3
+GITHUB_CLIENT_SECRET=2ea1f***********************e9da7
+OAUTH_CALLBACK_URL=http://localhost:8001/hub/oauth_callback

Set it like this.

Start-up

$ docker run -it -p 8001:8000 --env-file=env jupyter/oauthenticator

So, when you access it from a browser ...

スクリーンショット 2015-10-12 0.13.20.png

Kita━━━━ (゜ ∀ ゜) ━━━━ !!

Recommended Posts

Try building JupyterHub with Docker
Try Selenium Grid with Docker
Rails application building with Docker
Let's try gRPC with Go and Docker
Try building PySide2
[Python3] [Ubuntu16] [Docker] Try face recognition with OpenFace
Try building an environment for MayaPython with VisualStudioCode
Tftp server with Docker
Try scraping with Python.
Try SNN with BindsNET
Proxy server with Docker
Hello, World with Docker
Try regression with TensorFlow
A memo about building a Django (Python) application with Docker
Try to factorial with recursion
Try function optimization with Optuna
Try deep learning with TensorFlow
Try edge detection with OpenCV
Try using Jupyter's Docker image
Try Google Mock with C
Try using matplotlib with PyCharm
Try programming with a shell!
Try GUI programming with Hy
Try an autoencoder with Pytorch
Try Python output with Haxe 3.2
Try matrix operation with NumPy
Try implementing XOR with PyTorch
Try running CNN with ChainerRL
Try various things with PhantomJS
Try Deep Learning with FPGA
PySpark life starting with Docker
Prepare python3 environment with Docker
Try running Python with Try Jupyter
Try implementing perfume with Go
Try face recognition with Python
Try OpenCV with Google Colaboratory
Try machine learning with Kaggle
Try TensorFlow MNIST with RNN
Try using folium with anaconda
(Note) Notes on building TensorFlow + Flask + Nginx environment with Docker Compose
Building a kubernetes environment with ansible 2
Try Deep Learning with FPGA-Select Cucumbers
Try scraping with Python + Beautiful Soup
Try running tensorflow on Docker + anaconda
Japaneseize Matplotlib with Alpine using Docker
Until you start Jupyter with Docker
Easy Slackbot with Docker and Errbot
Try to operate Facebook with Python
Creating a Flask server with Docker
Build a deb file with Docker
Tips for running Go with docker
Try singular value decomposition with Python
Try deep learning with TensorFlow Part 2
Build Mysql + Python environment with docker
Deploy a Django application with Docker
Try http-prompt with interactive http access
Try audio signal processing with librosa-Beginner
Try horse racing prediction with Chainer
Google App Engine development with Docker
Try to profile with ONNX Runtime
Build PyPy execution environment with Docker