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
# 关闭浏览器重新访问

作者:jruing

出处:https://www.cnblogs.com/jruing/p/15943834.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Jruing  阅读(2210)  评论(4编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示