commit e186450ac03f0ec220b207b370a322eca1c656a2 Author: root Date: Wed Jun 11 07:42:51 2025 +0000 0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 0000000..9e94bc9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +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 + diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..4db2245 --- /dev/null +++ b/init.sh @@ -0,0 +1,32 @@ +#!/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 diff --git a/jupyterhub_config.py b/jupyterhub_config.py new file mode 100755 index 0000000..f7812c4 --- /dev/null +++ b/jupyterhub_config.py @@ -0,0 +1,25 @@ +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'] +