Skip to content

Instantly share code, notes, and snippets.

@jtpio
Last active February 3, 2020 12:44
Show Gist options
  • Save jtpio/b81954d43f3be3718905752fb820426a to your computer and use it in GitHub Desktop.
Save jtpio/b81954d43f3be3718905752fb820426a to your computer and use it in GitHub Desktop.
JupyterHub + Dockerspawner + Named server + Multiple images

Local JupyterHub with DockerSpawner and multiple images

A test config for running JupyterHub locally with:

  • DockerSpawner as a spawner
  • named servers enabled

named-servers-images

Setup

docker pull jupyter/scipy-notebook
docker pull jupyter/r-notebook

conda create -n jhub-local-docker -c conda-forge jupyterhub dockerspawner jupyter_client
conda activate jhub-local-docker

python -m jupyterhub -f jupyterhub_config.py --debug
c = get_config() # noqa
import os
from jupyterhub.auth import DummyAuthenticator
from dockerspawner import DockerSpawner
from jupyter_client.localinterfaces import public_ips
c.JupyterHub.hub_ip = public_ips()[0]
c.JupyterHub.allow_named_servers = True
c.JupyterHub.authenticator_class = DummyAuthenticator
images = {
'python': 'jupyter/scipy-notebook',
'r': 'jupyter/r-notebook',
}
class CustomSpawner(DockerSpawner):
def start(self):
self.image = images.get(self.name, images['python'])
return super().start()
c.CustomSpawner.default_url = '/lab'
c.CustomSpawner.remove = True
c.CustomSpawner.name_template = "{prefix}-{username}-{imagename}-{servername}"
# uncomment to show the image dropdown
# c.CustomSpawner.image_whitelist = images
c.JupyterHub.spawner_class = CustomSpawner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment