繁体   English   中英

无法从 docker 访问 jupyter notebook

[英]Can't access jupyter notebook from docker

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

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。

这是对我有用的:

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

$ 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

docker-machine ip对我不起作用,但它帮助我思考如何启动我的 docker 守护进程。

如果您的 docker 守护进程通过 minikube 运行,您可以使用以下命令获取 minikube 集群的 ip addr

minikube ip

使用从中获得的 ip addr 代替 127.0.0.1。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM