Home:ALL Converter>How to run JupyterHub/JupyterLab entirely on a prefix url behind traefik

How to run JupyterHub/JupyterLab entirely on a prefix url behind traefik

Ask Time:2020-11-02T16:49:29         Author:Rutger

Json Formatter

I have access to a single subdomain, subdomain.domain.com, on which I run several services behind traefik. In order to route the requests to the right server, I am setting the traefik router rules to distinguish the PathPrefix.

JupyterHub is one of the services I am running, which I am trying to run in "subdomain.domain.com/jupyterhub". By setting c.JupyterHub.bind_url="http://:8000/jupyterhub", I can have JuptyerHub work that way. But the servers it spawns with the dockerspawner are still running on "/user/{username}", and not on "/jupyterhub/user/{username}". I figure it must be a JupyterLab option I have to set, but I cannot figure out how.

My setup (relevant sections):

docker-compose.yaml:

version: '3.5'

services:

    jupyterhub:
        build: ./jupyterhub
        expose:
          - 8000
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - ./jupyterhub/ssl.crt:/srv/jupyterhub/ssl.crt
          - ./jupyterhub/ssl.key:/srv/jupyterhub/ssl.key
          - /etc/hostname:/srv/jupyterhub/host_hostname:ro
        networks:
            - traefik_proxy
        labels:
            - "traefik.enable=true"
            - "traefik.docker.network=traefik_proxy"
            - "traefik.http.services.jupyterhub.loadbalancer.server.port=8000"
            - "traefik.http.services.jupyterhub.loadbalancer.server.scheme=https"
            - "traefik.http.routers.jupyterhub.entrypoints=websecure"
            - "traefik.http.routers.jupyterhub.rule=Host(`subdomain.domain.com`) && (PathPrefix(`/jupyterhub`) || PathPrefix(`/hub`) || PathPrefix(`/user`))"
            - "traefik.http.routers.jupyterhub.tls=true"
            - "traefik.http.routers.jupyterhub.middlewares=strip-jupyterhub@docker"
            - "traefik.http.middlewares.strip-jupyterhub.stripprefix.prefixes=/jupyterhub"

jupyterhub/Dockerfile:

FROM jupyterhub/jupyterhub:1.3.dev
RUN apt-get update && apt-get -y install sssd gcc python3-dev
RUN pip install dockerspawner oauthenticator PyJWT netifaces
ADD jupyterhub_config.py /srv/jupyterhub

jupyterhub/jupyterhub_config.py:

<snip>
c.DockerSpawner.image = 'jupyter/datascience-notebook:lab-2.1.1'
c.JupyterHub.bind_url = 'http://:8000/jupyterhub/'
<snip>

This setup works, but only because I have added the PathPrefix(/user) in the traefik rule and I am stripping '/jupyterhub/' from the URL using traefik middleware. The JupyterHub spawner redirects everything to 'subdomain.domain.com/user/{username}', and I don't know how to run it on 'subdomain.domain.com/jupyterhub/user/{username}'.

Author:Rutger,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64642375/how-to-run-jupyterhub-jupyterlab-entirely-on-a-prefix-url-behind-traefik
yy