【问题标题】:How to run JupyterHub/JupyterLab entirely on a prefix url behind traefik如何完全在 traefik 后面的前缀 url 上运行 JupyterHub/JupyterLab
【发布时间】:2020-11-02 08:49:29
【问题描述】:

我可以访问单个子域 subdomain.domain.com,我在 traefik 后面运行多个服务。为了将请求路由到正确的服务器,我正在设置 traefik 路由器规则以区分 PathPrefix。

JupyterHub 是我正在运行的服务之一,我试图在“subdomain.domain.com/jupyterhub”中运行它。通过设置 c.JupyterHub.bind_url="http://:8000/jupyterhub",我可以让 JupyterHub 以这种方式工作。但是它使用 dockerspawner 生成的服务器仍在“/user/{username}”上运行,而不是在“/jupyterhub/user/{username}”上运行。我认为它必须是我必须设置的 JupyterLab 选项,但我不知道如何设置。

我的设置(相关部分):

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>

此设置有效,但只是因为我在 traefik 规则中添加了 PathPrefix(/user) 并且我正在使用 traefik 中间件从 URL 中删除“/jupyterhub/”。 JupyterHub 生成器将所有内容重定向到“subdomain.domain.com/user/{username}”,我不知道如何在“subdomain.domain.com/jupyterhub/user/{username}”上运行它。

【问题讨论】:

  • 你有想过这个吗?我现在正在尝试做同样的事情。

标签: docker docker-compose traefik jupyter-lab jupyterhub


【解决方案1】:

我最终使用了类似的设置,但没有 traefik 'stripprefix' 中间件或 '/user' 和 '/hub' 的 PathPrefix 规则,它似乎工作得很好。

【讨论】:

  • 你能提供一个示例代码吗?我无法让它工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 2019-12-08
  • 1970-01-01
  • 1970-01-01
  • 2022-06-22
相关资源
最近更新 更多