Build jupyterlab-notebook image from external environment

Sample 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

Production steps

  1. Create a new Dockerfile in the mirror production directory, the example is as above
  2. The required dependent files are decompressed and placed in the same directory
  3. docker build -t jupyterlab-test:1.0 .

Local verification

  1. docker run -it -p8888:8888 jupyterlab-test:1.0bash
  2. vi /usr/local/bin/jupyter_notebook_config.py can be modified to the following two contents (see dockerfile for specific file content)
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = True
  1. The specific instructions jump to the jupyter_notebook_config.py path, first execute jupyter lab to get the token to
    run
    Run jupyter notebook, access the displayed URL address (127.0.0.1 needs to be replaced with the physical machine ip) to
    verify whether it can be started normally, and use the jupyterlab interface

Guess you like

Origin blog.csdn.net/qq122716072/article/details/112218848