JupyterHub with Docker Spawner and Docker Swarm
See original GitHub issueHello,
So I’m trying to run JupyterHub using Docker Spawner and Docker Swarm and running it locally. I’m following your workshop tutorial here : dockerspawner. I want to run it locally without using carina, in order to deploy laterly to other cloud services using Docker Swarm. So I started my own Docker Swarm as it explained here : dockerswarm.
Based own your explanation, I’ve got this configuration files:
- launch.sh
#!/bin/sh
set -euo pipefail
export DNSNAME=localhost
export JUPYTERHUB_USERS=myself
export JUPYTERHUB_ADMINS=myself
export OAUTH_CLIENT_ID=<my_oauth_client_id>
export OAUTH_CLIENT_SECRET=<my_oauth_client_secret>
#export OAUTH_CALLBACK_URL=http://localhost:8000/hub/oauth_callback
docker build -t myjupyterhub .
#docker pull jupyterhub/singleuser
docker run --detach \
--name jupyterhub \
-p 80:8000 \
-p 8081:8081 \
-e DOCKER_CERT_PATH=${DOCKER_CERT_PATH} \
-e JUPYTERHUB_USERS=${JUPYTERHUB_USERS} \
-e JUPYTERHUB_ADMINS=${JUPYTERHUB_USERS} \
-e DOCKER_HOST=https://${DOCKER_HOST#tcp://} \
-e HUB_IP_CONNECT=${DNSNAME} \
-e OAUTH_CALLBACK_URL=http://${DNSNAME}/hub/oauth_callback \
-e OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} \
-e OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} \
myjupyterhub
open http://$(docker port jupyterhub 8000)
- jupyter_config.py
import os
import re
c = get_config()
c.JupyterHub.hub_ip = "0.0.0.0"
c.JupyterHub.spawner_class = "dockerspawner.DockerSpawner"
c.DockerSpawner.tls_verify = True
c.DockerSpawner.tls_ca = "/etc/docker/ca.pem"
c.DockerSpawner.tls_cert = "/etc/docker/server-cert.pem"
c.DockerSpawner.tls_key = "/etc/docker/server-key.pem"
c.DockerSpawner.container_ip = "0.0.0.0"
c.DockerSpawner.hub_ip_connect = os.environ["HUB_IP_CONNECT"]
c.JupyterHub.authenticator_class = "oauthenticator.GoogleOAuthenticator"
c.JupyterHub.login_url = "/hub/oauth_login"
def userlist(varname):
"""
Intercept an environment variable as a whitespace-separated list of GitHub
usernames.
"""
parts = re.split("\s*,\s*", os.environ[varname])
return set([part for part in parts if len(part) > 0])
c.Authenticator.whitelist = userlist("JUPYTERHUB_USERS")
c.Authenticator.admin_users = userlist("JUPYTERHUB_ADMINS")
c.GitHubOAuthenticator.oauth_callback_url = os.environ["OAUTH_CALLBACK_URL"]
c.GitHubOAuthenticator.client_id = os.environ["OAUTH_CLIENT_ID"]
c.GitHubOAuthenticator.client_secret = os.environ["OAUTH_CLIENT_SECRET"]
- Dockerfile
FROM jupyterhub/jupyterhub
RUN pip install --upgrade pip
RUN pip install dockerspawner oauthenticator
The container with the JupyterHub and DockerSpawner is created in the swarm, it launches the JupyterHub login page but with the System User authentification, and not the Google authentification sign up as I thought. So here come my questions.
I made the changes to try to make it works locally (without carina) like here jupyterhub-tutorial. I don’t see when the jupyter_config.py is called by JupyterHub. Do I have to add this file to the Dockerfile (and in the same way, the certificate and server key) ? So the created image is the container that launches the JupyterHub with DockerSpawner.
Where do I have to call the image with the notebook I want to spawn by Docker Spawner ? I have already created another docker image with Jupyter and my notebook (the singleuser image).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
So, after long week of search, I’m little disappointed to have no found any examples or tutorials explaining how to simply deploy jupyterhub with dockerspawner in a docker swarm locally, without using any cloud solution like Carina by Rackspace with jupiterhub-carina or OpenStack with Zonca tutorial. Nevertheless, I’ve learned so much about Docker and JupyterHub, thanks respectively to the teams developing such great tools.
So here a combined solution with all jupyterhub projects, posts and help found:
So, to sum up what I’ve done until now:
Do not mix up the standalone Docker Swarm and the Docker Engine Swarm mode. Dockerspawner runs with Docker Swarm (for the moment).
Use Docker Compose to ease the build, run and deploy process.
You can generate your own SSL certificate and key here: certificates-and-security or openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs
Here is my configuration:
I’m now facing two problems.
Using Google OAuth for the authentification process, dockerspawner spawn the container with the email of the user for naming the container (by replacing special characters). It seems not working with an attached volume. dockerspawner failed to spawn with the associated volume data if it contains special characters. It seems like the {username} parameter in the jupyterhub_config.py does not escape characters like @.
After deploying the swarm with virtual machines (VirtualBox under Mac OS X), one node as a swarm manager and another as a node, I run the JupyterHub container in the swarm manager, but the dockerspawner always spawn to the swarm manager node, and not to the agent node. The network is created and the dockerspawner is configured to be able to deploy to the configured network (see above).
The first thing missing in the original post appears to be a small typo: the config file should be
jupyterhub_config.py
, notjupyter_config.py
. And it must be loaded by JupyterHub. If you want to do this automatically, you can useFROM jupyterhub/jupyterhub-onbuild
instead ofFROM jupyterhub/jupyterhub
. Or, you can add the config file manually, withADD jupyterhub_config.py /srv/jupyterhub/jupyterhub_config.py
in your Dockerfile.