美文网首页
容器中部署 jupyter

容器中部署 jupyter

作者: momo1023 | 来源:发表于2019-11-06 15:29 被阅读0次

    python 环境

    构建 python 环境可参考:dcoker 构建基于 centos7 的 python3.6 镜像环境

    创建容器

    假设已有基于 centos 的 python 镜像,拉起一个容器。注意留一个端口

    $ docker run -it -p 18888:8888 --name jupyter_env ${docker_image}
    

    假如需要进入环境

    $ docker exec -it jupyter_env /bin/bash
    

    安装 jupyter

    $ pip install pyltp -i http://mirrors.aliyun.com/pypi/simple/   --trusted-host mirrors.aliyun.com
    

    配置 jupyter 环境

    $ find / -name jupyter
    

    显示信息如下:

    /usr/local/python3/bin/jupyter
    /usr/local/python3/share/jupyter
    /usr/local/python3/etc/jupyter
    

    将 jupyter 添加到环境变量中

    $ vim /etc/profile
    

    添加内容

    export PATH=$PATH:/usr/local/python3/bin/
    

    更新使配置生效

    $ source /etc/profile
    

    配置 jupyter

    $ jupyter notebook --generate-config
    

    显示结果如下:

    Writing default config to: /root/.jupyter/jupyter_notebook_config.py
    

    配置登录密码

    $ python3
    >>> from notebook.auth import passwd
    >>> passwd()
    

    结果如下:

    Enter password:
    Verify password:
    'sha1:e273930d6de1:bbebdcf3ded76dd11bb97a9c3f64fc2643291981'
    

    修改 jupyter 配置文件:

    c.NotebookApp.password = u'sha1:e273930d6de1:bbebdcf3ded76dd11bb97a9c3f64fc2643291981'
    c.NotebookApp.port = 8888  # 端口
    c.NotebookApp.ip = '*'  # 所有 ip 都可访问
    c.NotebookApp.open_browser = False
    

    保存退出,并设置防火墙(如果需要的话)

    $ firewall-cmd --zone=public --add-port=8888/tcp --permanent
    $ systemctl restart firewalld.service
    

    启动 jupyter

    $ nohup jupyter notebook --allow-root --ip=0.0.0.0 >jupyter.log &
    

    nohup 保证 session 关闭不会使得进程挂掉,& 后台运行,>jupyter.log 将日志输出到 jupyter.log 文件中

    浏览器登录

    地址 http://0.0.0.0:18888/tree
    需要输入密码,密码为上文设置的密码

    相关文章

      网友评论

          本文标题:容器中部署 jupyter

          本文链接:https://www.haomeiwen.com/subject/zjpubctx.html