如何使用docker-compose来安装jupyterhub

首先克隆我自己创建的仓库

git clone https://git.cnbugs.com/cnbugs/jupyter-docker-compose.git

进入仓库直接执行

docker-compose up -d

该仓库有三个文件

执行完之后使用8000端口号登录,默认账号是jupyterhub,默认密码是123456,密码可以在init.sh里边自行修改。

docker-compose.yml

version: '3'
services:
  jupyterhub:
    image: jupyterhub/jupyterhub:latest
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py
      - ./init.sh:/init.sh
    ports:
      - 8000:8000 
    command: /bin/bash /init.sh 123456

init.sh

#!/bin/bash
# 创建用户
useradd jupyterhub
echo "jupyterhub:$1" | chpasswd

# 检查是否已经安装了必要的工具和库文件
if ! dpkg -s python3-dev build-essential libffi-dev libssl-dev >/dev/null 2>&1; then
  # 安装必要的工具和库文件
  apt-get update && apt-get install -y \
      python3-dev \
      build-essential \
      libffi-dev \
      libssl-dev
fi

# 检查是否已经安装了JupyterHub
if ! pip list | grep jupyterhub >/dev/null 2>&1; then
  # 安装JupyterHub
  pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyterhub
fi

# 检查是否已经安装了Notebook
if ! pip list | grep notebook >/dev/null 2>&1; then
  # 安装Notebook
  pip install -i https://pypi.tuna.tsinghua.edu.cn/simple notebook
fi
# 配置JupyterHub
mkdir -p /home/jupyterhub
chown jupyterhub:jupyterhub /home/jupyterhub -R
chmod -R 777 /home
# 启动JupyterHub
jupyterhub

jupyterhub_config.py

c = get_config()

c.Authenticator.allow_all = True
c.Authenticator.allow_existing_users = True
# 管理员用户列表
c.Authenticator.admin_users = {'jupyterhub'}
# c.DummyAuthenticator.password = "jupyterhub"  # 初始密码设置
c.JupyterHub.admin_access = True
c.LocalAuthenticator.create_system_users=True

#c.Authenticator.admin_users = {'root'}  # 管理员用户
#c.DummyAuthenticator.password = "123"  # 初始密码设置

# 使用 PAMAuthenticator 作为身份验证类
c.JupyterHub.authenticator_class = 'jupyterhub.auth.PAMAuthenticator'
# 允许自动创建系统用户
c.LocalAuthenticator.create_system_users = True


 
# 设置每个用户的 book类型 和 工作目录(创建.ipynb文件自动保存的地方)
c.Spawner.notebook_dir = '~'
c.Spawner.default_url = '/lab'
c.Spawner.args = ['--allow-root'] 

发表回复

后才能评论