【问题标题】:Can't access jupyter notebook from docker无法从 docker 访问 jupyter notebook
【发布时间】:2019-11-25 14:52:47
【问题描述】:

我正在尝试运行在 Docker 中创建的 jupyter notebook。

首先我运行一个容器:

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 notebook 时:

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

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

【问题讨论】:

    标签: docker jupyter-notebook docker-container


    【解决方案1】:

    这对我有用:

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

    $ 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
    

    【讨论】:

      【解决方案2】:

      我要做的是使用命令获取 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
      

      【讨论】:

        【解决方案3】:

        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
        

        如果其他电脑需要访问,还是要指定docker主机ip。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-23
          • 1970-01-01
          • 1970-01-01
          • 2023-04-06
          相关资源
          最近更新 更多