无法从 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
据称找不到文件或无法访问该站点。我做错了什么?
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or
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
我必须做的是使用命令获取 docker-机器的 IP 地址:
docker-machine ip
然后用我拿到的ip代替命令给的ip:
Or copy and paste one of these URLs:
http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab
以下是对我有用的方法:
来自另一个终端 运行 以下命令:
$ 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 中 运行ning 并且您想从非 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 地址
minikube ip
使用从中获得的 ip 地址代替 127.0.0.1。
我正在尝试 运行 在 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
据称找不到文件或无法访问该站点。我做错了什么?
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or
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
我必须做的是使用命令获取 docker-机器的 IP 地址:
docker-machine ip
然后用我拿到的ip代替命令给的ip:
Or copy and paste one of these URLs:
http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab
以下是对我有用的方法:
来自另一个终端 运行 以下命令:
$ 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 中 运行ning 并且您想从非 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 地址minikube ip
使用从中获得的 ip 地址代替 127.0.0.1。