<>为概念标记,在实际输入中不用输入这个
main step:
1,配置docker-主机 端口映射
docker run -it -P <image> /bin/bash
其中-it 是以交互的方式打开镜像文件
-P 为<image>随机配置端口,将主机端口随机映射到docker端口,也可采用-p <主机端口>:<docker端口> ,指定主机端口映射
随机指定的情况下主机端口和对应的docker上被映射的端口可通过docker命令查看
查看启动的container的端口
docker ps ##docker端口信息位于 PORTS列
docker ps
docker port <conteiner ID>
2. 安装vim
mv /etc/apt/sources.list /etc/apt/sources.list.bak #复制
安装清华源
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" >>/etc/apt/sources.list
#echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" >>/etc/apt/sources.list
#echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" >>/etc/apt/sources.list
#echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" >>/etc/apt/sources.list
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" >>/etc/apt/sources.list
#echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" >>/etc/apt/sources.list
更新源,安装vim
apt-get update
apt-get install vim
3. 安装jupyter
pip install jupyter
# 生成配置文件,一般位置为:~/.jupyter/jupyter_notebook_config.py
jupyter-notebook --generate-config
ipython
# ipython 模式内输入
from notebook.auth import passwd
passwd(algorithm='sha1')
##复制sha密钥,后面jupyter配置需要用到
4,jupyter 配置
vim ~/.jupyter/jupyter_notebook_config.py
修改如下内容
c.NotebookApp.ip = '*' # 允许任意本地服务器的ip访问;
c.NotebookApp.port = 22 # 用于访问的端口,这里与前面Container的22端口要一致,如`-p 80:22`,这里填`22`;需要修改;
c.NotebookApp.open_browser = False # 不自动打开浏览器;不需要修改;
c.NotebookApp.allow_remote_access = True #允许远程访问;不需要修改;
c.NotebookApp.password = u'sha1:f264c28fe637:dedb448e6fa6eae5244044d2dac9ce9cc334f919' # 设置登录密码,把前面的密钥替换这里密钥;需要修改;
运行
jupyter notebook --allow-root
5,客户端登陆
客户端在浏览器输入:http://<主机ip>:<主机端口>
reference:Jupyter Notebook连接Docker环境
网友评论