简体   繁体   English

无法从 docker 访问 jupyter notebook

[英]Can't access jupyter notebook from docker

I am trying to run a jupyter notebook created in Docker.我正在尝试运行在 Docker 中创建的 jupyter notebook。

Firstly I run a container:首先我运行一个容器:

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

What I get is:我得到的是:

[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

But when I try to open Jupyter notebook on Chrome:但是当我尝试在 Chrome 上打开 Jupyter notebook 时:

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

It is written that file was not found or that site can't be reached.上面写着找不到文件或无法访问该站点。 What am I doing wrong?我究竟做错了什么?

What I had to do was to get ip address of the docker-machine using command:我必须做的是使用命令获取 docker-machine 的 IP 地址:

docker-machine ip

Then use the ip I got instead of the one given in the command:然后使用我得到的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 file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or或者
http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

This just mean if you open browser in container, you could do above.这只是意味着如果您在容器中打开浏览器,则可以执行上述操作。

When you start it in container and want to open browser on host or other machine, you surely need to do some changes, in your case it should be next:当您在容器中启动它并想在主机或其他机器上打开浏览器时,您肯定需要做一些更改,在您的情况下应该是下一个:

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

And if just open browser on docker host, then also could use:如果只是在 docker 主机上打开浏览器,那么也可以使用:

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

Or或者

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

If other pc need to visit, you still had to specify the docker host ip.如果其他电脑需要访问,你仍然需要指定docker主机ip。

Here's what worked for me :这是对我有用的:

from another terminal run following command :从另一个终端运行以下命令:

$ 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

As @atline mentioned, if you open browser in container, you could hit the url present on terminal.正如@atline 提到的,如果你在容器中打开浏览器,你可以点击终端上的 url。 But most likely your browser is not running in the docker and you want to access Dockerized jupyter from non-Dockerized browser.但是很可能您的浏览器没有在 docker 中运行,并且您想从非 Dockerized 浏览器访问 Dockerized jupyter。

In your url change the host and port as below:在您的 url 中更改主机和端口,如下所示:

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

Will be changed to :将改为:

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

docker-machine ip didn't work for me but it helped me think about how I start my docker daemon. docker-machine ip对我不起作用,但它帮助我思考如何启动我的 docker 守护进程。

If your docker daemon is running via minikube you can get the ip addr for your minikube cluster with如果您的 docker 守护进程通过 minikube 运行,您可以使用以下命令获取 minikube 集群的 ip addr

minikube ip

Use the ip addr you get from that in place of 127.0.0.1.使用从中获得的 ip addr 代替 127.0.0.1。

Try changing the port configuration in optional setting when running the new container to port 80 and call with http://127.0.0.1/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab (eliminating the port 8888 in the given address, as 80 is the default).尝试在运行新容器时将可选设置中的端口配置更改为端口 80,并使用http://127.0.0.1/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab 调用(消除给定地址中的端口 8888,因为 80 是默认值)。 That worked for me.那对我有用。

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

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