Docker安装miniconda配置Jupyter

Docker安装miniconda配置Jupyter

启用容器

1
2
3
4
5
6
docker run -id \
-p 8884:8888 \
--name miniconda \
--restart always \
-v /data/miniconda:/data \
--user root continuumio/miniconda3:latest

容器内安装jupyter notebook

更新apt-get

1
apt-get update

安装python dev包

1
apt-get install python-dev

安装jupyter

1
pip install jupyter

配置jupyter notebook

配置包括可以外部访问、设置密码、端口号、防火墙关闭。

首项,jupyter notebook默认端口为8888,并且不允许docker外部访问,想要开启必须配置jupyter_notebook_config.py文件。

首先初始化jupyter_notebook_config.py

1
jupyter notebook --generate-config

使用ipython生成密钥

ipython

1
2
3
from notebook.auth import passwd

passwd()

注意保存生成的密钥

编辑jupyter_notebook_config.py

1
vim /root/.jupyter/jupyter_notebook_config.py

设置c.NotebookApp.password,注意前面加 u

1
c.NotebookApp.password=u'生成的一串密钥'

设置外部访问

1
2
3
4
5
6
7
8
# 连通性设置
c.NotebookApp.allow_remote_access = True
# ip设置
c.NotebookApp.ip='*'
# 禁止自动打开浏览器
c.NotebookApp.open_browser = False
# 端口设置
c.NotebookApp.port = XXXX

启动jupyter notebook

1
jupyter notebook

放行linux防火墙:

放行你所设置的端口防火墙

注意映射问题

1
sudo firewall-cmd --zone=public --add-port=XXXX/tcp --permanent

重启防火墙

1
sudo systemctl restart firewalld

即可正常从网页端访问jupyter notebook,第一次需要输入密钥,以后会记住密钥。

个性化设置

安装jupyter notebook的插件。

安装插件前记住停止jupyter notebook

pip安装插件

1
pip install jupyter_contrib_nbextensions

配置 nbextension

1
jupyter contrib nbextension install --user --skip-running-check

重启jupyter notebook

1
jupyter notebook

选取插件控制器:

推荐以下插件:

Table of Contents (2):根据markdown的标题栏自动生成目录,有个按钮,可以自动添加数字编号;
Code prettify:对代码进行格式化;
Collapsible Headings:可以根据headings折叠区域;
Codefolding:可以对代码块进行折叠;
ScrollDown:当代码输出内容过长,自动下拉滚动条;

jupyter插件其他功能自行查找示例!
下面配置工作目录,首次打开会是根目录‘/’下的工作环境,不太方便,按个人需求配置。

编辑/root/.jupyter/jupyter_notebook_config.py

1
vim /root/.jupyter/jupyter_notebook_config.py

修改路径

1
c.NotebookApp.notebook_dir = 'XXX'

重新启动jupyter notebook

1
jupyter notebook

Docker安装miniconda配置Jupyter
https://leo03w.github.io/2022/12/03/Docker安装miniconda配置Jupyter/
作者
Leo
发布于
2022年12月3日
许可协议