使用Docker部署远程jupyter服务器
使用Docker部署远程服务的好处我就不过多赘述了,你不知道Docker的话应该也不会打开这篇博文
一 阿里云(或其他远程服务器提供商)安全组配置对应的端口

二 拉取官方推荐的镜像
Docker - Anaconda documentation
docker pull continuumio/miniconda
docker images

三 创建本地(宿主机)文件夹用来映射存放容器内的jupyter文件
mkdir /root/anaconda/jupyter
四 创建Docker容器
docker run -itd --name jupyter -p 8888:8888 -v /root/anaconda/jupyter:/root/anaconda/jupyter continuumio/miniconda3 /bin/bash
- -itd 交互式后台运行
- —name 容器名
- -p 端口映射 宿主机端口:容器端口
- -v 文件路径映射 宿主机路径:容器路径
- <continuumio/miniconda3> 镜像名,其实更推荐填写镜像ID
- <bin/bash> 进入容器后的命令
查看结果

五 进入容器内
docker exec -it <容器ID> bash
六 容器内操作
- 查看conda版本(确认安装成功)
- 安装jupyter
- 升级系统安装vim用来编辑配置文件
conda --version
conda install jupyter
apt-get update
apt-get install vim
01 生成jupyter配置
jupyter notebook --generate-config
02 设置登录密码
jupyter notebook password
Enter password: yourcode
Verify password: yourcodeagain
03 修改配置文件
vim ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.notebook_dir = '/root/anaconda/jupyter'
c.NotebookApp.allow_remote_access = True
04 后台运行jupyter
nohup jupyter notebook --allow-root &
05 然后按 Ctrl+p+q 退出交互式容器(不打断容器内进程)
七 回到宿主机shell
docker ps
访问<宿主机公网IP>:端口号 (例如1.2.3.4:8888) 登录即可远程使用jupyter

此时Jupyter的工作目录就是我们之前设置好的的工作目录(/root/anaconda/jupyter)
编辑的文件也会保存在宿主机的映射目录内(同为:/root/anaconda/jupyter)
网上同类型文章很多,已经找不到源出处了,本文结合相关文章使用Docker容器技术部署了远程Jupyter服务.
出处:微光小九 (B站同名)
|