参考链接:
cuda 镜像:https://hub.docker.com/r/nvidia/cuda
仿照 base-notebook:https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile
基础镜像;
base-notebook gpu
问题点:
镜像里安装的 tensorflow ,在制作镜像的时候可能会适配设备,导致在容器运行过程中无法识别GPU,不默认安装 TensorFlow,采用启动容器后自行安装。
docker 配置
[root@localhost ~]# cat /etc/docker/daemon.json
{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
}
}
nvidia 相关版本
libnvidia-container-tools-1.0.5-1.x86_64
nvidia-container-runtime-3.1.4-1.x86_64
nvidia-detect-440.36-1.el7.elrepo.x86_64
libnvidia-container1-1.0.5-1.x86_64
nvidia-container-toolkit-1.0.5-2.x86_64
nvidia-docker2-2.2.2-1.noarch
宿主机cuda版本:
cuda-9.2
dockerfile 涉及的相关脚本从 https://github.com/jupyter/docker-stacks/tree/master/base-notebook 自行下载。即可通用 gpu jupyterhub singleuser
FROM cuda:10.0-cudnn7-devel-ubuntu18.4
USER root
COPY start.sh /usr/local/bin/
COPY start-notebook.sh /usr/local/bin/
COPY start-singleuser.sh /usr/local/bin/
COPY jupyter_notebook_config.py /etc/jupyter/
ADD pip.conf /etc/pip.conf
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
wget \
bzip2 \
ca-certificates \
sudo \
locales \
fonts-liberation \
run-one \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
locale-gen
ENV CONDA_DIR=/opt/conda \
SHELL=/bin/bash \
NB_USER=$NB_USER \
NB_UID=$NB_UID \
NB_GID=$NB_GID \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
ENV PATH=$CONDA_DIR/bin:$PATH \
HOME=/home/$NB_USER
ADD fix-permissions /usr/local/bin/fix-permissions
RUN chmod a+rx /usr/local/bin/fix-permissions
RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc
RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
sed -i -e 's/^%admin/#%admin/' /etc/sudoers && \
sed -i -e 's/^%sudo/#%sudo/' /etc/sudoers && \
useradd -m -s /bin/bash -N -u $NB_UID $NB_USER && \
mkdir -p $CONDA_DIR && \
chown $NB_USER:$NB_GID $CONDA_DIR && \
chmod g+w /etc/passwd && \
fix-permissions $HOME && \
fix-permissions "$(dirname $CONDA_DIR)"
USER $NB_UID
WORKDIR $HOME
ARG PYTHON_VERSION=default
RUN mkdir /home/$NB_USER/work && \
fix-permissions /home/$NB_USER
RUN cd /tmp && \
wget --quiet http://bds.17usoft.com/cloud/package/rpm/Miniconda3-latest-Linux-x86_64.sh && \
/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p $CONDA_DIR && \
rm -f Miniconda3-latest-Linux-x86_64.sh && \
$CONDA_DIR/bin/conda config --system --prepend channels conda-forge && \
$CONDA_DIR/bin/conda config --system --set auto_update_conda false && \
$CONDA_DIR/bin/conda config --system --set show_channel_urls true && \
$CONDA_DIR/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ && \
$CONDA_DIR/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ && \
$CONDA_DIR/bin/conda config --set show_channel_urls yes && \
$CONDA_DIR/bin/conda install --quiet --yes conda && \
$CONDA_DIR/bin/conda update --all --quiet --yes && \
conda clean --all -f -y && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
RUN conda install --quiet --yes 'tini=0.18.0' && \
conda list tini | grep tini | tr -s ' ' | cut -d ' ' -f 1,2 >> $CONDA_DIR/conda-meta/pinned && \
conda clean --all -f -y && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
RUN conda install --quiet --yes \
'notebook=6.0.0' \
'jupyterhub=1.0.0' \
'jupyterlab=1.2.1' && \
conda clean --all -f -y && \
rm -rf $CONDA_DIR/share/jupyter/lab/staging && \
rm -rf /home/$NB_USER/.cache/yarn && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
USER root
RUN fix-permissions /etc/jupyter/
USER $NB_UID