python - Docker - 连接到 Jupyter notebook

标签 python docker jupyter-notebook

我正在尝试在 docker 中运行 Jupyter 笔记本,因为我尝试了命令 -

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

Executing the command: jupyter notebook
[I 04:19:53.460 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 04:19:53.856 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
[I 04:19:53.856 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 04:19:53.859 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 04:19:53.859 NotebookApp] Jupyter Notebook 6.1.4 is running at:
[I 04:19:53.859 NotebookApp] http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
[I 04:19:53.859 NotebookApp]  or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
[I 04:19:53.859 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 04:19:53.861 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://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
     or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c

当我尝试使用以下 url 连接到笔记本时(我尝试了三种不同的浏览器)-

file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html 
OR  
http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c

我在使用 url 时收到错误代码 ERR_NAME_NOT_RESOLVED 无法立即访问网站的错误 -

http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c

浏览器会持续尝试连接一段时间,然后得到ERR_CONNECTION_RESET

我试图禁用我的 VPN。我还尝试使用 export no_proxy=127.0.0.1 设置 no_proxy 变量,但我仍然无法连接到 jupyter notebook。

操作系统 - Manjaro Linux,

docker 镜像 -

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
jupyter/scipy-notebook   latest              b8f7562c1262        4 days ago          2.7GB

任何关于如何排除故障和连接到笔记本电脑的帮助或指导都会很有帮助。

最佳答案

Or copy and paste one of these URLs:
        http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
     or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c

↑ 那是你的 docker 容器 IP 和主机名。您需要使用 docker 容器外部的 IP 进行连接。

比如你的docker主机(linux物理机)IP是192.168.0.100尝试访问

http://192.168.0.100:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c

如果您在这种情况下无法访问,请尝试通过运行来设置您的主机IP

docker run -p 192.168.0.100:8888:8888 jupyter/scipy-notebook 
  • 编辑 1. 如何检查打开的端口。

尝试运行

sudo netstat -ntpl | grep 8888

如果你会看到类似的东西

tcp6       0      0 :::8888                 :::*                    LISTEN      1234/docker-proxy

或者

tcp       0      0 0.0.0.0:8888                 0.0.0.0:*                    LISTEN      1234/docker-proxy

这意味着您的 docker 运行良好并将 8888 端口转发到所有本地 IP(包括本地主机)。
因此,如果您可以看到打开的端口但无法连接,则很可能是防火墙造成的。

关于python - Docker - 连接到 Jupyter notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64674676/

相关文章:

jupyter-notebook - Jupyter notebook 显示问题(隐藏标题和 maintoolbar 后)

pip - jupyter笔记本中conda安装和pip安装的区别

jquery - 使用 Selenium 等待 jQuery 弹出窗口加载

python - 从python中的 Pandas 系列中删除元素

Python:来自更高范围的变量 "referenced before assignment"

Python BeautifulSoup 在 CSV 中打印信息

docker - github 工作流程 : "ECONNREFUSED 127.0.0.1:***" error when connecting to docker container

ruby-on-rails - 构建期间 dockerized rails 应用程序中的私有(private) Github 存储库

docker - 是否可以从容器向主机执行Docker调用?

jupyter-notebook - 有没有办法在 Jupyter 中输出单元格的 "tail -f"