docker容器中jupyter自动补全配置和ssh配置
jupyter安装自动补全插件:
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install --user jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
在浏览器中进入打开的jupyter,选择Files running clusters nbextensions中的nbextensions。选择Hinterland,打开即可。
jupyter修改登录密码:
输入jupyter notebook --generate-config生成配置文件,位置为"/当前用户名/.jupyter/jupyter_notebook_config.py"。如root用户为:"/root/.jupyter/jupyter_notebook_config.py"
产生密码:
命令行输入:
python,进入python的编辑状态;接下来输入:
from notebook.auth import passwd
passwd()
输入密码,记录下生成的哈希密码sha1
打开配置文件,即上面产生的.py文件,设置c.NotebookApp.password=哈希值(注意要加sha1:);
设置默认打开的端口:c.NotebookApp.port = 8888
docker安装ssh:
首先更新apt-get update
输入命令apt-get install openssh-server
修改设置:vim /etc/ssh/sshd_config
PermitRootLogin改为yes
端口改为需要的端口
ssh打开或关闭的命令为:/etc/init.d/ssh start (or stop)
连接时输入的密码为用户的密码;例如用户为root,则输入root的密码(修改用户密码 passwd)
可以创建一个sh文件直接打开jupyter和ssh:
创建名为run.sh的文件,使用chmod命令加入可执行权限。
一些docker容器已经有了run_jupyter.sh文件,可以修改后运行,也可以直接将其替换为对应的命令。
输入vi run.sh,进行编辑;
输入以下内容:
#!/usr/bin/env bash
echo 'Begining to run run_jupyter.sh'
sh /run_jupyter.sh # 或者替换为nohup jupyter notebook "[email protected]" --allow-root --ip=0.0.0.0 --port=8000 > jupyter.out 2>&1 &等等
echo 'Running run_jupyter finished'
nohup /etc/init.d/ssh start > ssh.out 2>&1 &
echo 'Running run.sh finished'
运行run.sh文件,即可打开ssh和jupyter。
上述命令使用的是后台运行,需要关闭jupyter时,可以查找进程id,然后杀掉。
输入ps -aux | grep jupyter
输入kill -9 5265杀掉jupyter进行。
ssh可使用ssh的打开和关闭命令。
# 参考了一些文章,但具体那些已经忘记了