jupyter notebook 大家都使用过, 多人使用一台机器时考虑到环境隔离,数据及代码的隐私,jupyterhub更为合适,下面就分享下,我自己搭建jupyterhub时的dockerfile, docker下使用对新手搭建环境更友好哦。
搭建时遇到问题留言就好,看到就会回复。
jupyterhub dockerfile
from nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
run rm -f /etc/apt/sources.list.d/cuda.list
copy sources.list.18.04 /etc/apt/sources.list
copy conda_tuna.txt /root/.condarc
copy Python-3.7.9.tgz /tmp/Python-3.7.9.tgz
copy jupyterhub_config.py /tmp/jupyterhub_config.py
copy Anaconda3-5.2.0-Linux-x86_64.sh /tmp/anaconda.sh
# base apt package
run rm -fr /etc/apt/sources.list.d/*
run apt-get update
run apt-get install -y npm vim sudo wget git
# apt package for python3 make install
env DEBIAN_FRONTEND=noninteractive
run apt-get install -y build-essential python-dev python-setuptools python-pip python-smbus
run apt-get install -y build-essential libncursesw5-dev libgdbm-dev libc6-dev
run apt-get install -y zlib1g-dev libsqlite3-dev tk-dev
run apt-get install -y libssl-dev openssl
run apt-get install -y libffi-dev
# make install python 3.7.9
workdir /tmp
run tar -zxvf Python-3.7.9.tgz
workdir Python-3.7.9
run ./configure
run make && make install
run make clean
# jupyterhub and jupyterlab
run python3 -m venv /opt/jupyterhub/
run /opt/jupyterhub/bin/python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
run /opt/jupyterhub/bin/python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
run /opt/jupyterhub/bin/python3 -m pip install wheel
run /opt/jupyterhub/bin/python3 -m pip install jupyterhub jupyterlab jupyter_contrib_nbextensions
run /opt/jupyterhub/bin/python3 -m pip install ipywidgets
run /opt/jupyterhub/bin/jupyter nbextension enable --py widgetsnbextension
run apt-get install -y nodejs npm
run npm config set registry https://registry.npm.taobao.org
run npm install -g configurable-http-proxy
run mkdir -p /opt/jupyterhub/etc/jupyterhub/
workdir /tmp
copy jupyterhub_config.py /opt/jupyterhub/etc/jupyterhub/
# conda environment
run chmod +x /tmp/anaconda.sh && bash /tmp/anaconda.sh -ubfp /opt/conda
# run mkdir /opt/conda/envs/
run /opt/conda/bin/conda create --prefix /opt/conda/envs/python python=3.7 ipykernel
run /opt/conda/envs/python/bin/python -m ipykernel install --prefix=/opt/jupyterhub/ --name 'python' --display-name "Python (default)"
# add user
run chmod -R 777 /usr/local/share
workdir /
run useradd -m -s /bin/bash -p $(openssl passwd -crypt 'admin') admin
# run chown -R admin:admin /home/admin
# run chown -R admin:admin /opt
run usermod -aG root admin
# run jupyterhub
cmd ["/opt/jupyterhub/bin/jupyterhub", "-f", "/opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py"]
# conda_tuna.txt
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
# jupyterhub_config.py
c = get_config()
c.Spawner.debug = True
c.Spawner.default_url = '/lab'
c.Spawner.cmd = ['/opt/jupyterhub/bin/jupyterhub-singleuser']
c.Authenticator.admin_users = {'admin'}
c.LocalAuthenticator.create_system_users=True