docker安装jupyter+nginx

2018年11月09日 2330点热度 0人点赞 0条评论

记下来怎么用docker装jupyter然后nginx代理jupyter notebook

[title]创建jupyter容器[/title]

创建dockerfile

这里还是用的miniconda镜像。

docker push miniconda

新建文件夹,文件夹内编辑Dockerfile文件。

FROM continuumio/miniconda3:latest

RUN mkdir ~/.jupyter ~/jupyter-root \
    && conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ \
    && conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ \
    && conda install -y jupyter \
    && rm -rf /opt/conda/pkgs/* \
    && rm -rf /root/.conda/pkgs/* \
    && echo 'if [ -f "~/.jupyter/jupyter_notebook_config.py" ];then\njupyter notebook\nelse\necho "no config file"\njupyter notebook --allow-root --ip=0.0.0.0\nfi' > ~/run.sh 

EXPOSE 8888

CMD ["bash","/root/run.sh"]
创建镜像
docker build -t diypy:jupyter .
创建容器
docker run --name jupyter --restart always -v ~/jupyter-conf:/root/.jupyter -v ~/jupyter-root:/root/jupyter-root -d diypy:jupyter

(网络和端口映射什么的就不说了,能找到ip就可以)

创建配置文件
docker exec jupyter /opt/conda/bin/jupyter notebook --generate-config -y

配置文件在容器的~/.jupyter/jupyter_notebook_config.py,主机的~/jupyter-conf

创建密码
docker exec -i jupyter /opt/conda/bin/jupyter notebook password
修改配置文件
vi jupyter_notebook_config.py
重启容器
docker restart jupyter

[title]nginx配置站点[/title]

(我的服务器跑了n个网站,然而还想用443端口,只能nginx代理

配置文件抄自jupyter notebook服务端安装——基于Python3、nginx

server{
    listen 80;
    server_name {域名};
    location / {
        proxy_pass            http://{ip+端口};
        proxy_set_header      Host $host;
    }
    location ~ /api/kernels/ {
        proxy_pass            http://{ip+端口};
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
    location ~ /terminals/ {
        proxy_pass            http://{ip+端口};
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
}

over

[title]或者,直接pull一个镜像,更方便强大[/title]

jupyter/all-spark-notebook
docker run -d -u root -e GRANT_SUDO=yes -v /server/jupyter:/home/jovyan/work -v /server/web/conf/jupyter:/home/jovyan/.jupyter --name jupyter --restart always jupyter/all-spark-notebook

 

AIKAMINO

暂无