Skip to content

Instantly share code, notes, and snippets.

@jcboyd
Created November 9, 2016 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcboyd/c00c17f2670a83c02eaf67b7e4ebac8d to your computer and use it in GitHub Desktop.
Save jcboyd/c00c17f2670a83c02eaf67b7e4ebac8d to your computer and use it in GitHub Desktop.
Dockerfile for ubuntu 16.04 + CUDA 8.0 + Caffe for deep learning -- https://hub.docker.com/r/jcboyd/ubuntu-cuda-caffe/
# $ docker run \
# --device /dev/nvidia0:/dev/nvidia0 \
# --device /dev/nvidiactl:/dev/nvidiactl \
# --device /dev/nvidia-uvm:/dev/nvidia-uvm jcboyd/ubuntu-cuda-caffe
# Download base image
FROM ubuntu:16.04
# Set environment variables
ENV PATH "/usr/local/cuda-8.0/bin:$PATH"
ENV LD_LIBRARY_PATH "/usr/local/cuda-8.0/lib:$LD_LIBRARY_PATH"
# Set keyboard configuration in advance of installing CUDA
RUN apt-get update && apt-get install -yq keyboard-configuration
# Download wget
RUN apt-get -y install wget
# Download CUDA repo package
RUN wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.44-1_amd64.deb
# Install CUDA
RUN dpkg -i cuda-repo-ubuntu1604_8.0.44-1_amd64.deb
RUN apt-get update && apt-get -y install cuda
# N.B. installation may appear to pause here--be patient!
# Install Caffe dependencies
RUN apt-get -y upgrade
RUN apt-get install -y \
python-dev \
python-numpy \
python-scipy \
build-essential \
cmake \
git \
pkg-config \
libprotobuf-dev \
libleveldb-dev \
libsnappy-dev \
libhdf5-serial-dev \
protobuf-compiler \
libatlas-base-dev \
libopencv-dev \
libxml2-dev \
libxslt-dev \
libgflags-dev \
libgoogle-glog-dev \
liblmdb-dev
RUN apt-get install -y --no-install-recommends libboost-all-dev
# Download Caffe
RUN cd /opt && git clone https://github.com/BVLC/caffe
# Copy to Makefile.config
RUN cd /opt/caffe/ && cp Makefile.config.example Makefile.config
# Edit Makefile.config
RUN cd /opt/caffe/ && \
echo "PYTHON_INCLUDE := /usr/include/python2.7 /usr/lib/python2.7/dist-packages/numpy/core/include" >> Makefile.config && \
echo "WITH_PYTHON_LAYER := 1" >> Makefile.config && \
echo "INCLUDE_DIRS := \$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial" >> Makefile.config && \
echo "LIBRARY_DIRS := \$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial" >> Makefile.config
# Edit Makefile
RUN cd /opt/caffe/ && \
sed -i -e 's/NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)/NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)/g' Makefile
# Download pip
RUN apt-get install -y python-pip
RUN pip install --upgrade pip
# Install Caffe python requirements
RUN cd /opt/caffe/ && for req in $(cat python/requirements.txt); do pip install $req; done
# Compile Caffe
RUN cd /opt/caffe/ && make all
RUN cd /opt/caffe/ && make test
RUN cd /opt/caffe/ && make pycaffe
# Set environment variable for Caffe
ENV PATH $PATH:/opt/caffe/.build_release/tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment