• Docker搭建jupyterlab


    拉镜像

    docker pull captainji/jupyterlab
    

    启动jupyterlab服务

    docker run -d \
    -p 8888:8888 \
    -e JUPYTER_ENABLE_LAB=yes \
    -v /data/docker/jupyter:/usr/local/src/jupyterlab_workspace \
    -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
    -v /etc/timezone:/etc/timezone \
    --restart=always \
    --name JupyterLab captainji/jupyterlab
    

    获取jupyterlab 访问的token

    # 获取容器日志,看日志中的token
    docker logs JupyterLab
    
    ####################################
    [I 2022-02-27 21:41:33.955 ServerApp] http://3c12d28a99a2:8888/lab?token=97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c
    [I 2022-02-27 21:41:33.955 ServerApp]  or http://127.0.0.1:8888/lab?token=97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c
    [I 2022-02-27 21:41:33.955 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 2022-02-27 21:41:33.958 ServerApp] 
        
        To access the server, open this file in a browser:
            file:///root/.local/share/jupyter/runtime/jpserver-7-open.html
        Or copy and paste one of these URLs:
            http://3c12d28a99a2:8888/lab?token=97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c
         or http://127.0.0.1:8888/lab?token=97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c
    ####################################
    上面链接中的97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c 就是访问的token
    

    访问jupyterlab

    # 注意:云服务器的话必须开通端口8888的防火墙,否则访问不到
    http://服务器ip:8888/lab?token=97c99de9e4b3ea86ebf567d8e1290c11023d165b7351156c
    
    

    设置jupyterlab自定义密码访问

    查看jupyterlab 配置

    # 进入容器
    docker exec -it JupyterLab /bin/bash
    # 进入jupyterlab配置文件所在目录
    cd ~/.jupyter/
    # 利用ipython生成密码
    root@3c12d28a99a2:~/.jupyter# ipython
    Python 3.8.6 (default, Sep 25 2020, 09:36:53) 
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: from notebook.auth import passwd
    
    In [2]: passwd()
    Enter password: 
    Verify password: 
    Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$R7ikdjMB7JBPTsV/XZPwUA$WYIpSx6zvn9H2HI4XIEHyA'
    
    
    

    修改jupyterlab 配置文件

    vi jupyter_lab_config.py
    
    # 在配置文件底部增加以下内容(shift+g直接到文件底部)
    c.NotebookApp.password ='argon2:$argon2id$v=19$m=10240,t=10,p=8$R7ikdjMB7JBPTsV/XZPwUA$WYIpSx6zvn9H2HI4XIEHyA' #秘钥(上一步获取的密钥)
    

    重启jupyterlab容器

    docker restart JupyterLab
    # 关闭浏览器重新访问
    
  • 相关阅读:
    leetcode 53. Maximum Subarray 最大子数组和(中等)
    leetcode 322. Coin Change 零钱兑换(中等)
    leetcode 72. Edit Distance 编辑距离(中等)
    leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
    leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
    leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
    leetcode 474. Ones and Zeroes 一和零(中等)
    聊聊量化投资项目以及项目总结
    面试题
    【leetCode]跳跃游戏
  • 原文地址:https://www.cnblogs.com/jruing/p/15943834.html
Copyright © 2020-2023  润新知