docker安装jupyter
我想jupyter官方提供了一些镜像搭建一个数学计算的docker容器,数学计算使用jupyter/datascience-notebook
比较合适但是下载失败,所以使用基础的镜像jupyter/base-notebook:latest
1. 安装jupyter/base-notebook镜像
docker pull jupyter/base-notebook:latest
docker run -p 80:8888 -v /docker/jupyter:/home/jovyan --name jupyter -d a954c1f0a0b5
# 网页中打开jupyter需要提供token,下面是查看token的方法
docker exec -it jupyter bash
jupyter notebook list
2. 安装数学计算的库
科学计算的库需要自己在jupyter/base-notebook:latest
容器中手工安装
conda install numpy
conda install sympy
conda install matplotlib
会有各种安装错误,所以使用pip安装
pip install matplotlib==3.5.3 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
3. 相关问题
3.1 新建文件/文件夹时报404错误
在配了nginx的情况下,新建文件/文件夹时报404错误,没有nginx的情况下就没有错误。
下面是jupyter的日志
[I 05:31:24.250 NotebookApp] http://c5fb810ccb74:8888/
[I 05:31:24.250 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 05:31:57.342 NotebookApp] Clearing invalid/expired login cookie username-172-17-0-1-8088
[W 05:31:57.343 NotebookApp] Forbidden
[W 05:31:57.343 NotebookApp] 403 GET /api/sessions?_=1687066139095 (172.17.0.1) 1.680000ms referer=http://jupyter.codingsprite.cn/tree?
[W 05:31:57.344 NotebookApp] Clearing invalid/expired login cookie username-172-17-0-1-8088
[W 05:31:57.344 NotebookApp] Forbidden
[W 05:31:57.345 NotebookApp] 403 GET /api/terminals?_=1687066139096 (172.17.0.1) 0.790000ms referer=http://jupyter.codingsprite.cn/tree?
[I 05:31:57.426 NotebookApp] 302 GET /tree? (172.17.0.1) 0.740000ms
[I 05:32:01.274 NotebookApp] 302 POST /login?next=%2Ftree%3F (172.17.0.1) 45.730000ms
[W 05:32:04.275 NotebookApp] Blocking Cross Origin API request for /api/contents. Origin: http://jupyter.codingsprite.cn, Host: 172.17.0.1:8088
[W 05:32:04.276 NotebookApp] Not Found
[W 05:32:04.276 NotebookApp] 404 POST /api/contents (172.17.0.1) 1.510000ms referer=http://jupyter.codingsprite.cn/tree?
[W 05:38:44.705 NotebookApp] Blocking Cross Origin API request for /api/contents. Origin: http://jupyter.codingsprite.cn, Host: 172.17.0.1:8088
[W 05:38:44.705 NotebookApp] Not Found
[W 05:38:44.705 NotebookApp] 404 POST /api/contents (172.17.0.1) 1.010000ms referer=http://jupyter.codingsprite.cn/tree
因为jupyter对于header有过滤,需要修改nginx配置将header复制,实例如下:
server {
server_name 127.0.0.1; # 入口地址
listen 80;
location /
{
proxy_pass http://127.0.0.1:8888; # jupyter服务器地址
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_next_upstream error;
#缓存相关配置
#proxy_cache cache_one;
#proxy_cache_key $host$request_uri$is_args$args;
#proxy_cache_valid 200 304 301 302 1h;
#持久化连接相关 WebSocket 配置
}
}
修改上面配置我就可了,有资料还要修改下面内容但是我不需要:
$ vi $HOME/jupyter/jupyter_notebook_config.py
c.NotebookApp.port = 8888
c.NotebookApp.base_url = '/jpy' 等
作者 :秋时
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。