Skip to content

Instantly share code, notes, and snippets.

@AkashiSN
Last active Dec 25, 2019
Embed
What would you like to do?
Jupyterlab docker
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04 as cuda
ENV DEBIAN_FRONTEND=noninteractive
ENV NVIDIA_DRIVER_CAPABILITIES utility,compute
ENV NVIDIA_VISIBLE_DEVICES all
RUN sed -i'~' -E "s@http://(..\.)?(archive|security)\.ubuntu\.com/ubuntu@http://jp.archive.ubuntu.com/ubuntu@g" /etc/apt/sources.list \
&& apt-get update \
&& apt-get install --yes --no-install-recommends \
build-essential \
bzip2 \
ca-certificates \
curl \
ffmpeg \
gawk \
git \
libavcodec-dev \
libavformat-dev \
libavresample-dev \
libcurl4-openssl-dev \
libglib2.0-0 \
libgtk-3-dev \
libgtk2.0-dev \
libguava-java \
libjpeg-dev \
libopenalpr-dev \
libopenblas-dev \
libopenni2-dev \
libpcl-dev \
libpng-dev \
libsm6 \
libswscale-dev \
libtbb-dev \
libtiff-dev \
libv4l-dev \
libxext6 \
libxrender1 \
mercurial \
openalpr \
openalpr-utils \
openni2-utils \
pkg-config \
primesense-nite-nonfree \
subversion \
unzip \
vim \
wget \
zlib1g-dev \
zsh \
&& rm -rf /var/lib/apt/lists/*
# Install Miniconda3
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh -O /tmp/anaconda.sh \
&& /bin/bash /tmp/anaconda.sh -b -p /opt/conda \
&& rm /tmp/anaconda.sh \
&& ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh \
&& . /etc/profile.d/conda.sh \
&& conda update -n base python -c defaults \
&& conda update -n base conda \
&& conda clean --all --yes \
&& conda install -y flake8 \
&& conda install -y tensorflow-gpu \
&& conda install -y pytorch torchvision -c pytorch \
&& conda clean --index-cache --tarballs --yes
# Install Cmake
RUN wget https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz -O /tmp/cmake-3.16.2.tar.gz \
&& cd /tmp && tar xvf cmake-3.16.2.tar.gz && cd cmake-3.16.2 \
&& ./configure --system-curl --system-zlib \
&& make -j "$(nproc)" \
&& make install \
&& make clean \
&& rm -rf /tmp/*
# Install OpenCV
RUN mkdir -p /tmp/opencv && cd /tmp/opencv \
&& wget https://github.com/opencv/opencv/archive/4.1.2.zip \
&& unzip 4.1.2.zip -d . \
&& mkdir opencv-4.1.2/build \
&& rm 4.1.2.zip \
&& wget https://github.com/opencv/opencv_contrib/archive/4.1.2.zip \
&& unzip 4.1.2.zip -d . \
&& cd opencv-4.1.2/build \
&& CUDA_PATH="/usr/local/cuda" CFLAGS="-I/usr/local/cuda/include" LDFLAGS="-L/usr/local/cuda/lib64" \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_EXAMPLES=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D CUDA_ARCH_BIN=7.5 \
-D CUDA_ARCH_PTX=7.5 \
-D CUDA_FAST_MATH=ON \
-D ENABLE_FAST_MATH=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_DNN_CUDA=ON \
-D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv/opencv_contrib-4.1.2/modules \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OpenBLAS_INCLUDE_DIR=/usr/include/x86_64-linux-gnu \
-D OpenBLAS_LIB=/usr/lib/x86_64-linux-gnu/libopenblas.so \
-D PYTHON3_EXECUTABLE=/opt/conda/bin/python \
-D PYTHON3_INCLUDE_DIR=/opt/conda/include/python3.7m \
-D PYTHON3_LIBRARY=/opt/conda/lib/python3.7/config-3.7m-x86_64-linux-gnu \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/opt/conda/lib/python3.7/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/opt/conda/lib/python3.7/site-packages \
-D PYTHON_DEFAULT_EXECUTABLE=/opt/conda/bin/python \
-D WITH_CUBLAS=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_FFMPEG=ON \
-D WITH_MKL=ON \
-D WITH_NVCUVID=OFF \
-D WITH_PYTHON=ON \
-D WITH_TBB=ON ..\
&& make -j "$(nproc)" \
&& make install \
&& /sbin/ldconfig \
&& make clean \
&& rm -rf /tmp/*
# Install darknet
RUN cd /usr/local/src && git clone https://github.com/AlexeyAB/darknet.git \
&& mkdir darknet/build_release && cd darknet/build_release \
&& ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1 \
&& cmake .. \
&& LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs/:$LD_LIBRARY_PATH make -j "$(nproc)" \
&& make install \
&& ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/lib/x86_64-linux-gnu/libcuda.so.1 \
&& ln -s /usr/local/src/darknet/darknet /usr/local/bin/darknet \
&& ln -s /usr/local/src/darknet/libdark.so /usr/local/bin/libdark.so
# Install .zshrc, zplug, vimrc
RUN wget -O $HOME/.zshrc https://gist.github.com/AkashiSN/4ff2eb541742bedb3d281725b6d15c3f/raw/zshrc \
&& wget -O $HOME/.vimrc https://gist.github.com/AkashiSN/4ff2eb541742bedb3d281725b6d15c3f/raw/vimrc \
&& git clone https://github.com/zplug/zplug $HOME/.zplug
# Install kernel
RUN /opt/conda/bin/ipython kernel install --user --name=python3.7 --display-name=python3.7
RUN /opt/conda/bin/pip install environment_kernels
RUN echo "y" | /opt/conda/bin/jupyter notebook --generate-config
RUN echo "c.MultiKernelManager.default_kernel_name = \"python3.7\"\n\
c.NotebookApp.allow_password_change = False\n\
c.NotebookApp.terminado_settings = { 'shell_command': ['/usr/bin/zsh'] }\n\
c.NotebookApp.password_required = True\n\
c.NotebookApp.allow_remote_access = True\n\
c.NotebookApp.ip = '0.0.0.0'\n\
c.NotebookApp.allow_origin = '*'\n\
c.NotebookApp.notebook_dir = '/Jupyter'\n" > $HOME/.jupyter/jupyter_notebook_config.py
RUN echo "cd /Jupyter" >> $HOME/.zshrc
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> $HOME/.zshrc
RUN echo "conda activate base" >> $HOME/.zshrc
#
# https://stackoverflow.com/questions/53910698/undefined-reference-to-ft-done-mm-var/56581845#56581845
#
RUN cp /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.10.1 /opt/conda/lib/libfontconfig.so.1.10.1 \
&& rm /opt/conda/lib/libfontconfig.so \
&& rm /opt/conda/lib/libfontconfig.so.1 \
&& ln -s /opt/conda/lib/libfontconfig.so.1.10.1 /opt/conda/lib/libfontconfig.so \
&& ln -s /opt/conda/lib/libfontconfig.so.1.10.1 /opt/conda/lib/libfontconfig.so.1
#
# https://stackoverflow.com/questions/40009184/error-importing-cv2-in-python3-anaconda/40077448
#
RUN cp /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.4000.14 /opt/conda/lib/libpangoft2-1.0.so.0.4000.14 \
&& rm /opt/conda/lib/libpangoft2-1.0.so \
&& rm /opt/conda/lib/libpangoft2-1.0.so.0 \
&& ln -s /opt/conda/lib/libpangoft2-1.0.so.0.4000.14 /opt/conda/lib/libpangoft2-1.0.so \
&& ln -s /opt/conda/lib/libpangoft2-1.0.so.0.4000.14 /opt/conda/lib/libpangoft2-1.0.so.0
ENTRYPOINT [ "/opt/conda/bin/jupyter", "lab", "--allow-root" ]
EXPOSE 8888
[Unit]
Description=Jupyter Lab
Requires=docker.service
After=docker.service
[Service]
Type=simple
ExecStartPre=-/usr/bin/docke stot JupyterLab
ExecStartPre=-/usr/bin/docker rm JupyterLab
ExecStart=/usr/bin/docker run -v /home/nishi/Jupyter:/Jupyter --name JupyterLab --gpus all -p 8888:8888 jupyter
ExecStop=/usr/bin/docker rm -f JupyterLab
[Install]
WantedBy=multi-user.target
@AkashiSN

This comment has been minimized.

Copy link
Owner Author

@AkashiSN AkashiSN commented Dec 11, 2019

build

sudo docker build -t jupyter:latest .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment