Docker容器配置Jupyter服务

在服务器的 Docker 容器中配置 Jupyter 服务,实现在 Windows 浏览器上远程调试代码的功能。

# 启动容器时绑定主机和docker的接口,jupyter服务的默认端口是8888
NV_GPU=0 nvidia-docker run -tid -v /home/code_directory jupyter:/home/code_directory -p 8877:8888 --name jupyter_serverce centos:7.5 /bin/bash
# 登录容器
docker exec -it jupyter_serverce /bin/bash --login

# 安装 jupyter
pip install jupyter notebook
# 配置jupyter notebook
jupyter notebook --generate-config
# 修改配置文件
vim ~/.jupyter/jupyter_notebook_config.py
# 第83行,允许远程访问
c.NotebookApp.allow_remote_access = True
# 第85行,允许root启动
c.NotebookApp.allow_root = True
# 第205行,监听任意的访问IP地址
c.NotebookApp.ip = '*'
# 第263行,加载默认的notebook文件夹,即容器启动时挂载的主机代码目录
c.NotebookApp.notebook_dir = '/home/code_directory'
# 第354行,设置默认token
c.NotebookApp.token = '1357'

# 启动notebook
# 容器内启动
jupyter notebook &
# 主机内启动
docker exec jupyter_serverce jupyter notebook &

# Windows浏览器打开容器中的代码目录
# http://[主机IP]:[绑定容器的端口]/tree?token=[配置文件中所设置的c.NotebookApp.token值]
http://10.37.2.190:8877/tree?token=1357
-------------本文结束 感谢阅读-------------
0%