无法从Docker访问jupyter笔记本

7dl7o3gd  于 2023-01-25  发布在  Docker
关注(0)|答案(5)|浏览(212)

我正在尝试运行在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

它写的文件没有找到或该网站无法到达。我做错了什么?

watbbzwu

watbbzwu1#

我所要做的是使用命令获取码头机器的IP地址:

docker-machine ip

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

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

kse8i1jr2#

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

如果其他电脑需要访问,你仍然需要指定的码头主机ip。

iklwldmw

iklwldmw3#

以下是对我有效的方法:
从另一个终端运行以下命令:

$ 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提到的,如果你在container中打开浏览器,你可以点击终端上的url,但很可能你的浏览器没有在Docker中运行,你想从非Dockerized浏览器访问Dockerized jupyter。
在您的网址中更改主机和端口如下:

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

将更改为:

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

aurhwmvo4#

docker-machine ip不适合我,但它帮助我思考如何启动我的docker守护进程。
如果您的docker守护进程通过minikube运行,您可以使用以下命令获取minikube集群的ip地址

minikube ip

使用从中获得的IP地址代替127.0.0.1。

yvt65v4c

yvt65v4c5#

尝试在运行新容器时将可选设置中的端口配置更改为端口80,并使用http://127.0.0.1/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab调用(删除给定地址中的端口8888,因为80是默认值)。

相关问题