无法在docker中访问jupyter笔记本

Rug*_*nar 4 docker jupyter-notebook

我想将 jupyter Notebook 安装到我的 docker 映像中。在容器中安装并运行它后,我无法从浏览器访问它。

\n

这是我的最小设置:

\n

Dockerfile:

\n
FROM python:3.7.5\nRUN pip install jupyterlab\nEXPOSE 8888\nCMD jupyter-lab --allow-root\n
Run Code Online (Sandbox Code Playgroud)\n

命令

\n
FROM python:3.7.5\nRUN pip install jupyterlab\nEXPOSE 8888\nCMD jupyter-lab --allow-root\n
Run Code Online (Sandbox Code Playgroud)\n

容器输出:

\n
    To access the server, open this file in a browser:\n        file:///root/.local/share/jupyter/runtime/jpserver-7-open.html\n    Or copy and paste one of these URLs:\n        http://localhost:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50\n     or http://127.0.0.1:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试打开这些链接中的任何一个,并在浏览器中收到此消息:

\n
This page isn\xe2\x80\x99t working\nlocalhost didn\xe2\x80\x99t send any data.\nERR_EMPTY_RESPONSE\n
Run Code Online (Sandbox Code Playgroud)\n

我究竟做错了什么?

\n

小智 7

默认情况下,Jupyter 配置为仅侦听 localhost 接口,您需要将其配置为侦听 0.0.0.0 (容器的 localhost 不是您的主机 localhost ..)

CMDDockerfile 中的行更改为CMD jupyter-lab notebook --ip 0.0.0.0 --port 8888 --allow-root

jupyter_notebook_config.py在容器/图像中编辑:更改以to
开头的行 并更改以to开头的行c.NotebookApp.allow_originc.NotebookApp.allow_origin = '*'
c.NotebookApp.ipc.NotebookApp.ip = '0.0.0.0'

使用这个问题寻求帮助:Why I can't access Remote Jupyter Notebook server?