Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
#
# This docker file was based on the dockerfile I obtained here:
# https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/gpu-jupyter.Dockerfile
#
# That's why I kept the copyright message above... however I changed/added a lot of stuff
# and fixed a bug where the autocomplete would not work because the image had no user home dir for UID 1000...
# I probably copied more stuff from other people's dockerfiles, but I forgot to take notes :(
# Life improvement if you are using VSCode:
# https://github.com/Microsoft/vscode-docker/issues/20#issuecomment-265326237
ARG UBUNTU_VERSION=16.04
FROM nvidia/cuda:9.0-base-ubuntu${UBUNTU_VERSION} as base
# My GeForce 940MX only works up to cuda9.0, anything above that will fail.
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cuda-command-line-tools-9-0 \
cuda-cublas-9-0 \
cuda-cufft-9-0 \
cuda-curand-9-0 \
cuda-cusolver-9-0 \
cuda-cusparse-9-0 \
curl \
libcudnn7=7.2.1.38-1+cuda9.0 \
libnccl2=2.2.13-1+cuda9.0 \
libfreetype6-dev \
libhdf5-serial-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
rsync \
software-properties-common \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && \
apt-get install nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0 && \
apt-get update && \
apt-get install libnvinfer4=4.1.2-1+cuda9.0 \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN file="$(ls -1 /usr/local/)" && echo $file
RUN apt-get -y update
RUN apt-get install -y --fix-missing \
build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-dev \
libavcodec-dev \
libavformat-dev \
libboost-all-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
python3-numpy \
software-properties-common \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
# For CUDA profiling, TensorFlow requires CUPTI.
ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
ARG PYTHON=python3
ARG PIP=pip3
# See http://bugs.python.org/issue19846
ENV LANG C.UTF-8
RUN apt-get update && apt-get install -y \
${PYTHON} \
${PYTHON}-pip
RUN ${PIP} --no-cache-dir install --upgrade \
pip \
setuptools
# Some TF tools expect a "python" binary
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python
# Options:
# tensorflow
# tensorflow-gpu
# tf-nightly
# tf-nightly-gpu
ARG TF_PACKAGE=tensorflow-gpu
RUN ${PIP} --no-cache-dir install ${TF_PACKAGE}
COPY bashrc /etc/bash.bashrc
RUN chmod a+rwx /etc/bash.bashrc
RUN ${PIP} --no-cache-dir install jupyter matplotlib pyinstrument
# RUN ${PIP} install jupyter matplotlib o pencv-python opencv-contrib-python pyinstrument
# Core linux dependencies.
RUN apt-get install -y --fix-missing \
build-essential \
cmake \
curl \
gfortran \
graphicsmagick \
git \
wget \
unzip \
yasm \
pkg-config \
libswscale-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libgraphicsmagick1-dev \
libjasper-dev \
libavformat-dev \
libhdf5-dev \
libpq-dev \
libgraphicsmagick1-dev \
libatlas-dev \
libavcodec-dev \
libboost-all-dev \
libgtk2.0-dev \
liblapack-dev \
liblapacke-dev \
libswscale-dev \
libcanberra-gtk-module \
libboost-dev \
libboost-all-dev \
libeigen3-dev \
# python3.6 \
python3-dev \
python3-numpy \
python3-scipy \
software-properties-common \
zip \
vim \
qt5-default \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
RUN ${PIP} --no-cache-dir install \
hdf5storage \
h5py \
py3nvml \
scikit-image \
scikit-learn
#
# OpenCV - compiles it with CUDA support
#
# To enable/disable CUDA support, you just need to change/exclude some of
# the build options like -DWITH_CUDA=ON (OFF), etc
WORKDIR /
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.1.zip
RUN wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.1.zip
RUN unzip opencv.zip
RUN unzip opencv_contrib.zip
RUN mv opencv-4.0.1 opencv
RUN mv opencv_contrib-4.0.1 opencv_contrib
RUN mkdir /opencv/build
WORKDIR /opencv/build
# ENV PATH="PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}"
# ENV LD_LIBRARY_PATH="LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
# https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound
# cmake -D CMAKE_BUILD_TYPE=RELEASE \
# -D CMAKE_INSTALL_PREFIX=/usr/local \
# -D INSTALL_PYTHON_EXAMPLES=ON \
# -D INSTALL_C_EXAMPLES=OFF \
# -D OPENCV_EXTRA_MODULES_PATH=/home/nicbet/Repositories/github.com/opencv/opencv_contrib/modules \
# -D PYTHON_EXECUTABLE=~/.virtualenvs/py3cv4/bin/python \
# -D BUILD_EXAMPLES=ON \
# -D WITH_CUDA=ON \
# -D CUDA_TOOLKIT_ROOT_DIR=/opt/cuda/9.2 ..
RUN cmake -DBUILD_TIFF=ON \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=ON \
-DENABLE_FAST_MATH=1 \
-DCUDA_FAST_MATH=1 \
-DWITH_CUBLAS=1 \
-DENABLE_AVX=ON \
-DWITH_OPENGL=ON \
# -DWITH_OPENCL=OFF \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=ON \
# -DBUILD_TESTS=OFF \
# -DBUILD_PERF_TESTS=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") \
-DPYTHON_EXECUTABLE=$(which python) \
-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DINSTALL_C_EXAMPLES=OFF \
-DOPENCV_ENABLE_NONFREE=ON \
-DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
-DBUILD_EXAMPLES=ON \
-D CUDA_TOOLKIT_ROOT_DIR=/opt/cuda/9.0 \
-DWITH_QT=ON ..
RUN make -j4 \
&& make install \
&& rm /opencv.zip \
&& rm /opencv_contrib.zip \
&& rm -rf /opencv \
&& rm -rf /opencv_contrib
WORKDIR /
# dlib
RUN cd ~ && \
mkdir -p dlib && \
git clone -b 'v19.16' --single-branch https://github.com/davisking/dlib.git dlib/ && \
cd dlib/ && \
python3 setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA --clean
RUN mkdir -p /tf/tensorflow-tutorials && chmod -R a+rwx /tf/
RUN mkdir /.local && chmod a+rwx /.local
RUN apt-get install -y --no-install-recommends wget
WORKDIR /tf/tensorflow-tutorials
RUN wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/basic_classification.ipynb
RUN wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/basic_text_classification.ipynb
RUN wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/overfit_and_underfit.ipynb
RUN wget https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/keras/save_and_restore_models.ipynb
RUN apt-get autoremove -y && apt-get remove -y wget
WORKDIR /tf
EXPOSE 8888
RUN useradd -ms /bin/bash container_user
RUN ${PYTHON} -m ipykernel.kernelspec
# CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --allow-root"]
CMD ["bash", "-c", "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root --NotebookApp.custom_display_url='http://localhost:8888'"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment