如何在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'