☰
【Docker】Docker: 如何在Docker中优雅地使用jupyter notebook (利器)
2026/10/23 4:02:59 网站建设 项目流程

如何在Docker中优雅地使用jupyter notebook

1. 安装jupyter

使用anaconda安装jupyter notebook

conda install jupyter notebook

2. 生成密码

在ubuntu的命令行里输入ipython打开ipython

ipython

在python命令行里分别输入:

from notebook.auth import passwd passwd()

会出现如下的密钥

In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:854d183417ac:db1e783bde7bbab704d009c996e93dc2d3e31c25'

这时候把sha1秘钥保存下来,然后退出ipython命令行:

quit

3. 生成jupyter notebook的配置文件

jupyter notebook --generate-config

这时候会生成配置文件,在 ~/.jupyter/jupyter_notebook_config.py

4. 配置对应文件

打开 ~/.jupyter/jupyter_notebook_config.py,加入一下内容:

sha1是之前生成的密钥

c.NotebookApp.ip='*' c.NotebookApp.password = u'sha1:854d183417ac:db1e783bde7bbab704d009c996e93dc2d3e31c25' c.NotebookApp.open_browser = False c.NotebookApp.port =5595

5595表明要使用container的5595端口访问jupyter,然后保存退出。之前配置容器的时候开放的端口

5. 打开jupyter notebook

jupyter notebook --allow-root

6. 遇到的问题:

可能会遇到如下的问题()

socket.gaierror: [Errno -5] No address associated with hostname

再次打开~/.jupyter/jupyter_notebook_config.py,添加ip如下,问题即可解决

c.NotebookApp.ip = '0.0.0.0'

7. 参考地址

  1. https://www.cnblogs.com/yangxiaolan/p/5778305.html

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询