jupyterhub_config.py
# Configuration file for jupyterhub.
import os
from jupyterhub.utils import random_port
from dockerspawner import DockerSpawner
class custom_spawner(DockerSpawner):
@property
def internal_hostname (self):
# Set FQDN or localhost
return 'localhost’
def _port_default (self):
#Do NOT set c.DockerSpawner.port in the config file
return random_port()
c.JupyterHub.bind_url = 'http://127.0.0.1:8000’
# DockerSpawner chosen as spawner for good isolation between users, particularly filesystem isolation
#c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner’
c.JupyterHub.spawner_class = custom_spawner
# Running Docker Stacks scipy-notebook image (hash specified for version known compatible
# with this jupyterhub install)
# Selecting an Image — Docker Stacks documentation
#c.DockerSpawner.image = 'jupyter/scipy-notebook:612aa5710bf9’
#c.DockerSpawner.image = 'jupyter/tensorflow-notebook:feacdbfc2e89’
c.DockerSpawner.image = '###'
# The docker instances need access to the Hub and can’t use the default loopback address - they
# need to use the public IP address of the Hub. A firewall rule is in place to allow access
# through the default port 8081.
from jupyter_client.localinterfaces import public_ips
c.JupyterHub.hub_ip = public_ips()[0]
# Explicitly set notebook directory because we’ll be mounting a host volume to
*# it. Most jupyter/docker-stacks -notebook images run the Notebook server as
# user jovyan
, and set the notebook directory to /home/jovyan/work
.
notebook_dir = os.environ.get( ‘DOCKER_NOTEBOOK_DIR’ ) or '/home/jovyan/work’
c.DockerSpawner.notebook_dir = notebook_dir
# Use a previously created docker network bridge
# network_name = 'jupyter’
# c.DockerSpawner.network_name = network_name
# c.DockerSpawner.extra_host_config = {‘network_mode’: network_name }
c.DockerSpawner.extra_host_config = { ‘network_mode’ : ‘host’ }
c.DockerSpawner.use_internal_hostname = True
c.DockerSpawner.network_name = 'host’
c.DockerSpawner.host_ip = '###'
# Using docker volume for persistance of user data. Mount the real user’s Docker
# volume on the host to the notebook user’s notebook directory in the container
c.DockerSpawner.volumes = { ‘jupyterhub-user-{username}’ : notebook_dir }
# And use a docker bind mount to get readonly access to course material in host
# directory.
c.DockerSpawner.read_only_volumes = { ‘/home/users/files’ : notebook_dir + “/files” }
# Set a user memory limit
c.DockerSpawner.mem_limit = '2G’
# be provided by jupyterhub database.
c.Authenticator.admin_users = set()
c.Authenticator.admin_users.add( ‘###’ )
c.Authenticator.whitelist = set()
c.Authenticator.whitelist.add( ‘###’ )
# Allow admin users to access other users’ notebooks
c.JupyterHub.admin_access = True
c.ConfigurableHTTPProxy.auth_token = '###'
c.JupyterHub.cookie_secret = b '###'
# We use a modified pam config which omits pam_access access list check - that list is used to
# restrict non-jupyterhub logins to this server, and the jupyterhub whitelist is used for hub
# logins.
c.PAMAuthenticator.service = 'jupyterhub’
#pg_pass = os.getenv(‘POSTGRES_ENV_JPY_PSQL_PASSWORD’)
pg_pass = '###'
#pg_host = os.getenv(‘POSTGRES_PORT_5432_TCP_ADDR’)
pg_host = '127.0.0.1’
c.JupyterHub.db_url = ‘postgresql://jupyterhub:{}@{}:5432/jupyterhub’ .format(
pg_pass, pg_host
)
c.Spawner.cmd=[ “jupyter-labhub” ]
#c.Spawner.http_timeout = 60
#c.Spawner.start_timeout = 60