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