因此,这是我想要实现的目标:
除了最后一部分,我或多或少已经实现了这一目标。我正在启动笔记本服务器,但无法访问外界。它只能访问Jupyter Hub(这就是它起作用的原因!),而不能访问其他任何内容。
这是我与DockerSpawner有关的Jupyter Hub配置(我省略了OAuth设置,因为这些设置可以正常工作。
# Tell JupyterHub that we want Docker Spawner to be used.
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
# And what image should be used by the Docker Spawner
c.DockerSpawner.image = 'jupyter/scipy-notebook:7a0c7325e470'
# The Hub must listen on all interfaces.
c.JupyterHub.hub_ip = '0.0.0.0'
# And this should be the address of the Hub API
c.JupyterHub.hub_connect_ip = 'jupyterhub'
# Ask containers to connect to this network so that they can
# communicate with the Hub.
c.DockerSpawner.network_name = 'djangodockerjupyterdemo_default'
# And let's not make a mess, remove user containers when done.
c.DockerSpawner.remove = True
# We need to set the Notebook Directory
notebook_dir = '/home/jovyan/work'
c.DockerSpawner.notebook_dir = notebook_dir
# Need to tell where to mount the volumes.
c.DockerSpawner.volumes = { 'jupyterhub-user-{username}': notebook_dir }
请注意,由于项目目录的名称如此,docker-compose正在创建
djangodockerjupyterdemo_default
。 (我知道这不是最好的事情,但是现在我只是希望有一个最小的例子可以工作。)这是我的 docker 组成:
version: "2"
services:
database:
image: "mysql:5.6"
volumes:
- ./data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=test123
- MYSQL_DATABASE=oauthserver
- MYSQL_USER=oauthadmin
- MYSQL_PASSWORD=test123
webapp:
image: auth_server:latest
volumes:
- ./:/app
links:
- database:database
environment:
- PYTHONUNBUFFERED=1
- ENV=DEV
- DATABASE_HOST=database
- DATABASE_USER=oauthadmin
- DATABASE_DBNAME=oauthserver
- DATABASE_PASSWORD=test123
hostname: oauthserver.ddi.in
jupyterhub:
image: "jupyterhub:test"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:rw"
- "./jupyterhub:/srv/jupyterhub"
environment:
- OAUTH2_AUTHORIZE_URL=http://oauthserver.ddi.in:8000/o/authorize
- OAUTH2_TOKEN_URL=http://oauthserver.ddi.in:8000/o/token/
hostname: jhtest.ddi.in
links:
- webapp:oauthserver.ddi.in
我使用https://hub.docker.com/r/defreitas/dns-proxy-server来访问JupyterHub服务器,方法是说“http://jhtest.ddi.in:8000”。
现在,一旦容器装满,我可以确认以下内容:
将
docker exec
编码到webapp
或jupyterhub
容器中,然后对Internet上某个位置的文件进行wget
起作用。 docker exec
插入生成的Jupyter笔记本容器中,而执行此操作不会。尝试从笔记本内部使用requests.get()
也是一样。 我如何使生成的笔记本能够访问外界?这对我的用例至关重要(我敢肯定,这是合理的期望)。
PS:我注意到几乎没有关于使用自定义Django应用程序进行OAuth JupyterHub设置的示例。我希望公开发布我的示例,希望它可以作为Jupyter Hub文档上的资源。
最佳答案
您可能想在Jupyter Discourse Forum上的'JupyterHub'类别下发表一个非常简短的文章,突出显示此文章以获得更多专家的关注。
关于docker - JupyterHub产生的Jupyter Notebook容器没有外部网络访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59871431/