Docker: 如何在Docker中优雅地使用jupyter notebook (利器)

如何在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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值