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
# 關閉瀏覽器重新訪問


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM