python - Jupyterhub/单用户共享卷

标签 python docker ubuntu-16.04 jupyter jupyterhub

我正在尝试在 Ubuntu 16.04 上设置 Jupyterhub 服务器,大致类似于 https://github.com/minrk/jupyterhub-demo

我使用此处给出的提示更改了 jupyterhub_config.py 以支持持久存储 https://github.com/jupyterhub/dockerspawner#data-persistence-and-dockerspawner :

notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
c.DockerSpawner.notebook_dir = notebook_dir
c.DockerSpawner.volumes = { 'jupyterhub-user-{username}': notebook_dir }

但是,我想为用户团队添加共享“团队”卷。我有一个包含用户名(键)和团队名(值)的字典,用于将用户映射到团队。

理想情况下我会这样说:

c.DockerSpawner.volumes = { 
    'jupyterhub-user-{username}': notebook_dir, 
    'jupyterhub-team-{teamname}': os.path.join(notebook_dir, 'shared' 
}

但我不知道如何将另一个 {name} 映射传递给 dockerspawner。

我尝试摆弄这些,但到目前为止没有成功:

c.DockerSpawner. ...
extra_create_kwargs = Dict(config=True, help="Additional args to pass for container create")
extra_start_kwargs = Dict(config=True, help="Additional args to pass for container start")
extra_host_config = Dict(config=True, help="Additional args to create_host_config for container create")

有什么想法吗?

P.S.:这个问题与Shared, writable folders in jupyterhub有些关系。

最佳答案

摘自您在GitHub收到的@minrk的回复在此处发布几周后。

For more advanced logic not exposed in the default config objects, you can also subclass DockerSpawner in your config file:

from dockerspawner import DockerSpawner
class MyDockerSpawner(DockerSpawner):
    def start(self):
        # username is self.user.name
        team = 'myteam'
        # add team volume to volumes
        self.volumes['jupyterhub-team-{}'.format(team)] = '/home/shared'
        return super().start()

c.JupyterHub.spawner_class = MyDockerSpawner

关于python - Jupyterhub/单用户共享卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44986021/

相关文章:

python - 圆环图 python

python - 自动恢复最小化的 tkinter 窗口

python - 从列表中获取素数

docker - 如何更新 Hyperledger Fabric 中的链码?

linux - 如何在 bash 脚本执行期间更改用户并继续使用新用户运行命令?

java - 在非root用户下启动tomcat 9

python - "not in"和 "is not"都是运算符吗?如果是这样,它们与 "not x in.."和 "not x is.."有什么不同吗?

运行回显命令的 Docker 参数

docker - 本地Docker与Kubernetes集群的连接

ubuntu-16.04 - 如何在ubuntu-16.04中安装apache?