无法从Docker访问Jupyter Notebook

时间:2019-07-16 19:53:54

标签: docker jupyter-notebook docker-container

我正在尝试运行在Docker中创建的jupyter笔记本。

首先,我运行一个容器:

docker run -p 8888:8888 jupyter/tensorflow-notebook

我得到的是:

[I 19:44:47.140 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 19:44:51.731 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.7/site-packages/jupyterlab
[I 19:44:51.732 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 19:44:51.742 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 19:44:51.743 NotebookApp] The Jupyter Notebook is running at:
[I 19:44:51.743 NotebookApp] http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab
[I 19:44:51.743 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 19:44:51.753 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
    Or copy and paste one of these URLs:
        http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

但是当我尝试在Chrome上打开Jupyter笔记本时:

file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or
http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

写到找不到文件或无法访问该站点。我在做什么错了?

3 个答案:

答案 0 :(得分:0)

  

file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
  或
  http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

这只是意味着,如果您在容器中打开浏览器,则可以执行以上操作。

当您在容器中启动它并要在主机或其他计算机上打开浏览器时,您肯定需要进行一些更改,在这种情况下,应该紧随其后:

http://$(YOUR_DOCKER_HOST_IP):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

如果只是在docker主机上打开浏览器,那么也可以使用:

http://localhost:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

http://127.0.0.1:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

如果需要访问其他PC,则仍然必须指定docker host ip。

答案 1 :(得分:0)

我要做的是使用命令获取docker-machine的IP地址:

docker-machine ip

然后使用我得到的IP代替命令中给出的IP:

Or copy and paste one of these URLs:
    http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

答案 2 :(得分:0)

这对我有用:

从另一个终端运行以下命令:

$ sudo docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                     NAMES
9137012fbde0        jupyter/base-notebook   "tini -g -- start-no…"   13 minutes ago      Up 13 minutes       0.0.0.0:10000->8888/tcp   happy_napier

正如@atline 提到的, 如果您在容器中打开浏览器,您可以点击终端上的 url。但很可能您的浏览器没有在 docker 中运行,而您想从非 Dockerized 浏览器访问 Dockerized jupyter。

在您的 url 中更改主机和端口,如下所示:

http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

将改为:

http://0.0.0.0:10000/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab