使用 docker 设置 Jupyterhub - TraitError

使用 docker 设置 Jupyterhub - TraitError

我正在尝试在 docker 上设置 jupyterlab。

我的解决方案基于https://opendreamkit.org/2018/10/17/jupyterhub-docker/主要的例外是使用本地 Linux 用户帐户授权。

登录后出现以下错误:

jupyterhub_hub   | [I 2019-03-10 18:59:01.297 JupyterHub dockerspawner:706] Found existing container jupyter-jlyskawa (id: 3a5c54c)
jupyterhub_hub   | [I 2019-03-10 18:59:01.297 JupyterHub dockerspawner:721] Starting container jupyter-jlyskawa (id: 3a5c54c)
jupyterhub_hub   | [E 2019-03-10 18:59:01.323 JupyterHub user:477] Unhandled error starting jlyskawa's server: The 'ip' trait of a Server instance must be a unicode string, but a value of None <class 'NoneType'> was specified.
jupyterhub_hub   | [E 2019-03-10 18:59:01.349 JupyterHub web:1670] Uncaught exception GET /hub/user/jlyskawa/ (::ffff:172.19.0.1)
jupyterhub_hub   |     HTTPServerRequest(protocol='http', host='172.19.0.4:8000', method='GET', uri='/hub/user/jlyskawa/', version='HTTP/1.1', remote_ip='::ffff:172.19.0.1')
jupyterhub_hub   |     Traceback (most recent call last):
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
jupyterhub_hub   |         result = yield result
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/jupyterhub/handlers/base.py", line 1052, in get
jupyterhub_hub   |         await self.spawn_single_user(user)
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/jupyterhub/handlers/base.py", line 705, in spawn_single_user
jupyterhub_hub   |         timedelta(seconds=self.slow_spawn_timeout), finish_spawn_future
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/jupyterhub/handlers/base.py", line 626, in finish_user_spawn
jupyterhub_hub   |         await spawn_future
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/jupyterhub/user.py", line 489, in spawn
jupyterhub_hub   |         raise e
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/jupyterhub/user.py", line 420, in spawn
jupyterhub_hub   |         server.ip = urlinfo.hostname
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 585, in __set__
jupyterhub_hub   |         self.set(obj, value)
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 559, in set
jupyterhub_hub   |         new_value = self._validate(obj, value)
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 591, in _validate
jupyterhub_hub   |         value = self.validate(obj, value)
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 2054, in validate
jupyterhub_hub   |         self.error(obj, value)
jupyterhub_hub   |       File "/opt/conda/lib/python3.6/site-packages/traitlets/traitlets.py", line 625, in error
jupyterhub_hub   |         raise TraitError(e)
jupyterhub_hub   |     traitlets.traitlets.TraitError: The 'ip' trait of a Server instance must be a unicode string, but a value of None <class 'NoneType'> was specified.

有没有什么办法可以修复或者解决这个问题?

附加信息:

目录结构:

docker
+-- .env
+-- docker_compose.yml
+-- jupyterhub/
|   +-- Dockerfile
|   +-- jupyter-config.py
+-- jupyterlab/
|   +-- Dockerfile
+-- reverse-proxy/
    +-- traefik.toml

.环境:

COMPOSE_PROJECT_NAME=my_hub

docker-compose.yml:

version: '2'
services:
  # Configuration for Hub+Proxy
  jupyterhub:
    build: jupyterhub
    container_name: jupyterhub_hub
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
      - /etc/shadow:/etc/shadow:ro
    environment:                     # Env variables passed to the Hub process.
      DOCKER_JUPYTER_IMAGE: jupyterlab_img
      DOCKER_NETWORK_NAME: ${COMPOSE_PROJECT_NAME}_default
      HUB_IP: jupyterhub_hub
    labels:                          # Traefik configuration.
      - "traefik.enable=true"
      - "traefik.docker.network=${COMPOSE_PROJECT_NAME}_default"
  # Configuration for reverse proxy
  reverse-proxy:
    image: traefik
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - ./reverse-proxy/traefik.toml:/etc/traefik/traefik.toml
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/certs:/etc/certs
  # Configuration for the single-user servers
  jupyterlab:
    build: jupyterlab
    container_name: jupyterlab_img
    command: echo
    environment:
      JUPYTER_ENABLE_LAB: 'yes'

jupyterhub/Dockerfile:

FROM jupyterhub/jupyterhub:0.9.4

USER root

COPY jupyterhub_config.py .

RUN pip install \
    dockerspawner==0.10.0

jupyterhub/jupyter-config.py:

import os

c.JupyterHub.admin_access = True
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
c.DockerSpawner.image = os.environ['DOCKER_JUPYTER_IMAGE']
c.DockerSpawner.network_name = os.environ['DOCKER_NETWORK_NAME']
c.DockerSpawner.debug = True
c.JupyterHub.hub_ip = os.environ['HUB_IP']

c.JupyterHub.authenticator_class = 'jupyterhub.auth.PAMAuthenticator'

jupyterlab/Dockerfile:

FROM jupyter/datascience-notebook

RUN conda install --quiet --yes \
    'r-base=3.4.1' \
    'r-irkernel=0.8*'&& \
    conda clean -tipsy


反向代理/traefik.toml:

debug = true

logLevel = "DEBUG"
defaultEntryPoints = ["http"]

# Redirect HTTP -> HTTPS, install certificates
[entryPoints]
  [entryPoints.http]
  address = ":80"

# Activate docker API
[docker]
domain = "docker.local"
watch = true

# Activate Traefik dashboard
[api]

答案1

看起来问题出在网络名称上,因为引用的链接中提出的网络名称不是默认的。

它还要求在重建之前删除所有容器(至少在docker-compose中指定)

更改的文件:

.环境:

COMPOSE_PROJECT_NAME=myhub

docker-compose.yml:

version: '2'
services:
  # Configuration for Hub+Proxy
  jupyterhub:
    build: jupyterhub
    container_name: jupyterhub_hub
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
      - /etc/shadow:/etc/shadow:ro
    environment:                     # Env variables passed to the Hub process.
      DOCKER_JUPYTER_IMAGE: jupyterlab_img
      DOCKER_NETWORK_NAME: ${COMPOSE_PROJECT_NAME}_default
      HUB_IP: jupyterhub_hub
    labels:                          # Traefik configuration.
      - "traefik.enable=true"
      - "traefik.docker.network=${COMPOSE_PROJECT_NAME}_default"
    network:
      - default
  # Configuration for reverse proxy
  reverse-proxy:
    image: traefik
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - ./reverse-proxy/traefik.toml:/etc/traefik/traefik.toml
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/certs:/etc/certs
    network:
      - default
  # Configuration for the single-user servers
  jupyterlab:
    build: jupyterlab
    container_name: jupyterlab_img
    command: echo
    environment:
      JUPYTER_ENABLE_LAB: 'yes'
    network:
      - default
networks:
  default:

相关内容