Skip to content

Instantly share code, notes, and snippets.

@Pk13055
Created May 30, 2019 12:17
Show Gist options
  • Save Pk13055/dca0015ddbf81738039d1e462d20f4db to your computer and use it in GitHub Desktop.
Save Pk13055/dca0015ddbf81738039d1e462d20f4db to your computer and use it in GitHub Desktop.
Ubuntu 16.04 docker with cuda-9.1, cudnn7, dlib, openCV, boost, ffmpeg
FROM nvidia/cuda:9.1-cudnn7-runtime-ubuntu16.04
MAINTAINER <hidden>
# env vars to be loaded at build
ARG http_proxy
ARG https_proxy
ARG no_proxy
ENV http_proxy=$http_proxy
ENV https_proxy=$https_proxy
ENV no_proxy=$no_proxy
ENV HTTP_PROXY=$http_proxy
ENV HTTPS_PROXY=$https_proxy
ENV NO_PROXY=$no_proxy
RUN apt-get -y update \
&& apt-get -y autoclean \
&& apt-get -y autoremove
# Install the C++ dependencies
RUN apt-get -y install clang \
build-essential \
cmake \
git \
libgtk2.0-dev \
pkg-config \
libavcodec-dev \
libavformat-dev \
libswscale-dev\
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libeigen3-dev \
liblapack-dev \
libatlas-base-dev \
libgomp1 \
libx264-dev
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
# dlib installation
ARG RUNTIME_DEPS='libpng libjpeg-turbo giflib openblas libx11'
ARG BUILD_DEPS='wget unzip cmake build-base linux-headers libpng-dev libjpeg-turbo-dev giflib-dev openblas-dev libx11-dev'
ARG LIB_PREFIX='/usr/local'
ARG DLIB_VERSION='19.17' # set this to update dlib version
ENV DLIB_VERSION=${DLIB_VERSION} \
LIB_PREFIX=${LIB_PREFIX} \
DLIB_INCLUDE_DIR='$LIB_PREFIX/include' \
DLIB_LIB_DIR='$LIB_PREFIX/lib'
RUN echo "Dlib: ${DLIB_VERSION}" \
&& rm -rf /usr/local/lib && ln -s /usr/local/lib64 /usr/local/lib \
&& apk add -u --no-cache $RUNTIME_DEPS \
&& apk add -u --no-cache --virtual .build-dependencies $BUILD_DEPS \
&& wget -q https://github.com/davisking/dlib/archive/v${DLIB_VERSION}.zip -O dlib.zip \
&& dlib_cmake_flags="-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$LIB_PREFIX \
-D DLIB_NO_GUI_SUPPORT=ON \
-D DLIB_USE_BLAS=ON \
-D DLIB_GIF_SUPPORT=ON \
-D DLIB_PNG_SUPPORT=ON \
-D DLIB_JPEG_SUPPORT=ON \
-D DLIB_USE_CUDA=ON" \
&& unzip -qq dlib.zip \
&& mv dlib-${DLIB_VERSION} dlib \
&& rm dlib.zip \
&& cd dlib \
&& mkdir -p build \
&& cd build \
&& cmake $dlib_cmake_flags .. \
&& make -j $(getconf _NPROCESSORS_ONLN) \
&& cd /dlib/build \
&& make install \
&& cp /dlib/dlib/*.txt $LIB_PREFIX/include/dlib/ \
&& cd / \
&& rm -rf /dlib \
&& /usr/glibc-compat/sbin/ldconfig \
&& apk del .build-dependencies \
&& rm -rf /var/cache/apk/* /usr/share/man /usr/local/share/man /tmp/*
# ffmpeg installation
ARG FFMPEG_VERSION="3.4" # change accordingly
RUN echo "ffmpeg: ${FFMPEG_VERSION}"
RUN wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2
RUN tar xvjf ffmpeg-${FFMPEG_VERSION}.tar.bz2
WORKDIR /root/ffmpeg-${FFMPEG_VERSION}
RUN ./configure --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame \
--enable-libvorbis --enable-libtheora --enable-libx264 --enable-libspeex --enable-shared --enable-pthreads \
--enable-libopenjpeg --enable-nonfree
RUN make
RUN make install
RUN /sbin/ldconfig
WORKDIR /root
RUN rm -rf /root/ffmpeg-${FFMPEG_VERSION}*
#install opencv
WORKDIR /
ENV OPENCV_VERSION="3.4.4" # set the version here
ENV OPENCV_CONTRIB_VERSION="3.4.4" # set the version here
RUN git clone https://github.com/opencv/opencv_contrib.git && cd opencv_contrib\
&& git checkout $OPENCV_CONTRIB_VERSION && cd ..
RUN git clone https://github.com/opencv/opencv.git
RUN cd opencv \
&& git checkout $OPENCV_VERSION \
&& mkdir build
&& cd build \
&& cmake -DBUILD_TIFF=ON \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=ON \
-DENABLE_FAST_MATH=1 \
-DCUDA_FAST_MATH=1 \
-DWITH_CUBLAS=ON \
-DWITH_OPENCL=ON \
-DUSE_FAST_MATH=ON \
-DWITH_QT=ON \
-DENABLE_AVX=ON \
-DWITH_OPENGL=ON \
-DWITH_IPP=ON \
-DWITH_FFMPEG=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=ON \
-DBUILD_TESTS=OFF \
-DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DBUILD_PERF_TESTS=OFF \
-DCMAKE_BUILD_TYPE=RELEASE ..\
&& make -j $(getconf _NPROCESSORS_ONLN) install
RUN /sbin/ldconfig
WORKDIR /root
# opencv depedencies
RUN apt-get update --fix-missing \
&& apt-get install -qqy \
libleveldb-dev \
liblmdb-dev \
libsnappy-dev \
python-skimage \
&& apt-get clean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*
# boost installation
WORKDIR /usr/include/
# We pass the boost version argument as argument
ARG BOOST_VERSION="1.70.0" # change boost version here
ARG BOOST_VERSION_="1_70_0" # same as above with diff format
ENV BOOST_VERSION=${BOOST_VERSION}
ENV BOOST_VERSION_=${BOOST_VERSION_}
ENV BOOST_ROOT=/usr/include/boost
RUN wget --max-redirect 3 https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_}.tar.gz
RUN mkdir -p /usr/include/boost && tar zxf boost_${BOOST_VERSION_}.tar.gz -C /usr/include/boost --strip-components=1
# misc video/image plugins installation
RUN apt-get update --fix-missing \
&& apt-get -qqy gstreamer-plugins-base1.0-dev libgstreamer1.0-dev \
&& ln -s /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h /usr/include/glib-2.0/ \
&& ln -s /usr/lib/x86_64-linux-gnu/gstreamer-1.0/include/gst/gstconfig.h /usr/include/gstreamer-1.0/gst/gstconfig.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment