title: Install OpenCV in a Docker container
body: <p>I'm attempting to Dockerise a Python application, which depends on OpenCV. I've tried several different ways, but I keep getting... <code>ImportError: No module named cv2</code> when I attempt to run the application. </p>
  
  <p>Here's my current Dockerfile.</p>
  
  <pre><code>FROM python:2.7
  
  MAINTAINER Ewan Valentine &lt;ewan@theladbible.com&gt;
  
  RUN mkdir -p /usr/src/app 
  WORKDIR /usr/src/app 
  
  # Various Python and C/build deps
  RUN apt-get update &amp;&amp; apt-get install -y \ 
      wget \
      build-essential \ 
      cmake \ 
      git \
      pkg-config \
      python-dev \ 
      python-opencv \ 
      libopencv-dev \ 
      libav-tools  \ 
      libjpeg-dev \ 
      libpng-dev \ 
      libtiff-dev \ 
      libjasper-dev \ 
      libgtk2.0-dev \ 
      python-numpy \ 
      python-pycurl \ 
      libatlas-base-dev \
      gfortran \
      webp \ 
      python-opencv 
  
  # Install Open CV - Warning, this takes absolutely forever
  RUN cd ~ &amp;&amp; git clone https://github.com/Itseez/opencv.git &amp;&amp; \ 
      cd opencv &amp;&amp; \
      git checkout 3.0.0 &amp;&amp; \
      cd ~ &amp;&amp; git clone https://github.com/Itseez/opencv_contrib.git &amp;&amp; \
      cd opencv_contrib &amp;&amp; \
      git checkout 3.0.0 &amp;&amp; \
      cd ~/opencv &amp;&amp; mkdir -p build &amp;&amp; cd build &amp;&amp; \
      cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \ 
      -D INSTALL_C_EXAMPLES=ON \ 
      -D INSTALL_PYTHON_EXAMPLES=ON \ 
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ 
      -D BUILD_EXAMPLES=OFF .. &amp;&amp; \
      make -j4 &amp;&amp; \
      make install &amp;&amp; \ 
      ldconfig
  
  COPY requirements.txt /usr/src/app/
  RUN pip install --no-cache-dir -r requirements.txt
  
  COPY . /usr/src/app 
  </code></pre>
  
  <p>And my requirements.txt file</p>
  
  <pre><code>Flask==0.8
  gunicorn==0.14.2
  requests==0.11.1
  bs4==0.0.1
  nltk==3.2.1
  pymysql==0.7.2
  xlsxwriter==0.8.5
  numpy==1.11
  Pillow==3.2.0
  cv2==1.0
  pytesseract==0.1
  </code></pre>