Docker 安装 notebook

参考文档

https://github.com/jupyter/docker-stacks
https://jupyter-docker-stacks.readthedocs.io/en/latest/using/running.html
https://jupyter-notebook.readthedocs.io/en/stable/config.html
https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#preparing-a-hashed-password
https://blog.csdn.net/Qwertyuiop2016/article/details/120439121
https://blog.csdn.net/love__guo/article/details/120549245

部署

这里使用 jupyter/scipy-notebook:2023-06-01 版本,这边拉回本地镜像仓库并改名

mkdir -p /data/docker-compose/notebook
cd /data/docker-compose/notebook

# 获取密码
docker run -it --rm devharbor.junengcloud.com/oversea/scipy-notebook:2023-06-01 bash
python
from notebook.auth import passwd
passwd()
# 我这里输入的密码为 123456
# 获取到加密后的值

## 这里有个需要注意的地方
## NotebookApp.password 中有 $跟字母的地方需要使用 $$ 来代替,如 $argon,需要改成 $$argon, $+ 这类则不需要

cd /data/docker-compose/notebook
vi docker-compose.yml
version: '3.4'
services:
  notebook:
    image: devharbor.junengcloud.com/oversea/scipy-notebook:2023-06-01
    network_mode: "host"
    deploy:
     resources:
        limits:
           cpus: '2'
           memory: 4G
    container_name: notebook
    volumes:
      - ./data:/home/jovyan/work
    command: bash -c "
      start-notebook.sh \
      --NotebookApp.password='argon2:$$argon2id$$v=19$$m=10240,t=10,p=8$+evuq/7CE8qmby9fuKvMVQ$$Fl9RVSl7akFjv+p+Fd1/QViYya9djceac2sg+AnGXgk' \
      --NotebookApp.allow_password_change=False \
      --NotebookApp.allow_remote_access=True \
      --NotebookApp.open_browser=False \
      --NotebookApp.notebook_dir='/home/jovyan/work'
      --NotebookApp.port=9999
      "
    restart: always

# 需要提前创建 data 目录, 并赋予权限
mkdir data
chown 1000.100 data

# 启动
docker-compose up -d

浏览器访问 http://服务器IP:9999/login,输入密码 123456

posted @ 2023-06-21 16:28  klvchen  阅读(139)  评论(0编辑  收藏  举报