Created
July 20, 2019 14:18
-
-
Save marufeuille/596cf6f9e26fa6fcb7e304d5b163c7c8 to your computer and use it in GitHub Desktop.
jupyterhub_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_name = "YOUR_CONTAINER_IMAGE_NAME" | |
network_name = "YOUR_DOCKER_NETWORK_NAME" | |
c.JupyterHub.authenticator_class = 'jupyterhub.auth.PAMAuthenticator' | |
from jupyter_client.localinterfaces import public_ips | |
c.JupyterHub.hub_ip = public_ips()[0] | |
c.JupyterHub.port = 8888 | |
from dockerspawner import DockerSpawner | |
import pwd, os, grp | |
class MyDockerSpawner(DockerSpawner): | |
def start(self): | |
name = self.user.name | |
user_data = pwd.getpwnam(name) | |
gid_list = os.getgrouplist(name, user_data.pw_gid) | |
self.volumes['jupyterhub-user-{username}'] = notebook_dir + '/personal' | |
for gid in gid_list: | |
gname = grp.getgrgid(gid).gr_name | |
if gname.startswith("project-"): | |
dirname = gname.replace("project-", "") | |
self.volumes[gname] = notebook_dir + "/project/" + dirname | |
return super().start() | |
c.JupyterHub.spawner_class = MyDockerSpawner | |
c.DockerSpawner.image = image_name | |
c.DockerSpawner.remove_containers = True | |
c.DockerSpawner.network_name = network_name | |
c.DockerSpawner.hub_ip_connect = public_ips()[0] | |
c.Spawner.http_timeout = 30 | |
c.Authenticator.admin_users = set() | |
c.PAMAuthenticator.open_sessions = False | |
notebook_dir = '/root/workspace' | |
c.DockerSpawner.notebook_dir = notebook_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment