欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

外部环境构建jupyterlab-notebook镜像

程序员文章站 2022-05-27 23:12:32
...

示例Dockerfile

FROM
# path conda
ENV PATH="/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda
/bin:${PATH}" \
NVIDIA_VISIBLE_DEVICES=all \
CONDA_DIR=/opt/conda \
MINICONDA_VERSION=4.7.5 \
SHELL=/bin/bash \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
HOME=/root
# tini
RUN env |grep -iE "cuda|nvidia|cudnn" | sed 's/^/export &/g' > /etc
/profile.d/cuda-env.sh && \
sed -i "s#$CONDA_DIR/bin:##g" /etc/profile.d/cuda-env.sh && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen && \
wget --quiet https://github.com/krallin/tini/releases/download/v0.10.0
/tini && \
echo "1361527f39190a7338a0b434bd8c88ff7233ce7b9a4876f3315c22fce7eca1b0
*tini" | sha256sum -c - && \
mv tini /usr/local/bin/tini && \
chmod +x /usr/local/bin/tini
RUN echo "set directory=/root/.vim/swapfiles/" > /root/.vimrc \
&& echo "set backupdir=/root/.vim/backups/" >> /root/.vimrc \
&& mkdir -p /root/.vim/swapfiles \
&& mkdir -p /root/.vim/backups
# jupyterlab
ADD . /src/jupyter
RUN npm config set registry http://registry.npm.taobao.org/ && \
cd /src/jupyter/jupyterhub && npm install --unsafe-perm && pip install
. && \
cp -R /src/jupyter/notebook /src/jupyter/jupyterhub && \
cp /src/jupyter/notebook/start.sh /usr/local/bin/ && \
cp /src/jupyter/notebook/start-notebook.sh /usr/local/bin/ && \
cp /src/jupyter/notebook/start-singleuser.sh /usr/local/bin/ && \
cp /src/jupyter/notebook/jupyter_notebook_config.py /usr/local/bin/ &&
\
cp /src/jupyter/bmlmodel/bmlmodel /usr/local/bin/ && \
cp /src/jupyter/bmlmodel/notebook_config.yaml /etc/ && \
pip --no-cache-dir install ipywidgets==7.5.0 -i https://pypi.tuna.
tsinghua.edu.cn/simple/ && \
pip --no-cache-dir install jupyterlab==1.2.6 -i https://pypi.tuna.
tsinghua.edu.cn/simple/ && \
jupyter serverextension enable --py jupyterlab && \
conda clean -ay && \
npm cache clean --force && \
rm -rf $CONDA_DIR/share/jupyter/lab/staging && \
rm -rf /root/.cache/yarn && \
rm -rf /root/.node-gyp && \
rm -rf /src/jupyter ~/.cache ~/.npm
EXPOSE 8888
WORKDIR $HOME
# Configure container startup
ENTRYPOINT ["tini", "--"]
CMD ["start-notebook.sh"]
# set timezone
COPY Shanghai /
RUN echo "set timezone" && \
rm -f /etc/localtime && \
mv /Shanghai /etc/localtime

制作步骤

  1. 在镜像制作目录下新建 Dockerfile,示例如上
  2. 需要的依赖文件解压后放在同级目录
  3. docker build -t jupyterlab-test:1.0 .

本地验证

  1. docker run -it -p8888:8888 jupyterlab-test:1.0bash
  2. vi /usr/local/bin/jupyter_notebook_config.py 修改为以下两项内容即可 (具体file内容参见dockerfile)
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = True
  1. 具体指令 跳转到 jupyter_notebook_config.py 路径下 先执行 jupyter lab 获取token
    运行
    运行 jupyter notebook ,访问展示出来的url地址(127.0.0.1需要替换成物理机ip)
    验证可不可以正常启动,和使用 jupyterlab 界面