title: Why does my Docker cache get invalidated by this COPY command?
body: <p>My docker builders in CI system get destroyed after inactivity, thus losing the local cache. I am using <code>--cache-from</code> by first pulling the most recent image from quay.io repo and then using that as a <code>--cache-from</code> in the next build. 
  I am running docker version <code>17.12.0-ce</code>.
  Dockerfile (for the pertinent part) looks like:</p>
  
  <pre><code>FROM ubuntu:16.04
  RUN apt-get update &amp;&amp; apt-get install -y \
  ant \
  build-essential \
  software-properties-common \
  libncurses5-dev \
  libncursesw5-dev \
  libcurl4-openssl-dev \
  libboost-dev \
  libfreetype6-dev \
  zlib1g-dev \
  r-base \
  default-jdk \
  python-dev \
  python-setuptools \
  python-pip \
  python3-dev \
  python3-setuptools \
  python3-pip \
  git \
  wget \
  unzip \
  ghostscript \
  pkg-config
  
  
  RUN mkdir /software
  WORKDIR /software
  ENV PATH="/software:${PATH}"
  
  RUN git clone --branch v0.2.19 --single-branch 
  https://github.com/xianyi/OpenBLAS
  RUN cd OpenBLAS &amp;&amp; make FC=gfortran TARGET=NEHALEM USE_THREAD=0 &amp;&amp; make 
  PREFIX=/opt/openblas install
  ENV LD_LIBRARY_PATH="/opt/openblas/lib:${LD_LIBRARY_PATH}"
  
  # Install samtools dependencies
  RUN wget http://zlib.net/zlib-1.2.11.tar.gz &amp;&amp; tar -xvf zlib-1.2.11.tar.gz
  RUN cd zlib-1.2.11 &amp;&amp; ./configure &amp;&amp; make &amp;&amp; make install
  RUN wget http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz &amp;&amp; tar -xvf bzip2-
  1.0.6.tar.gz
  RUN cd bzip2-1.0.6 &amp;&amp; make &amp;&amp; make install
  RUN wget https://tukaani.org/xz/xz-5.2.3.tar.gz &amp;&amp; tar -xvf xz-5.2.3.tar.gz
  RUN cd xz-5.2.3 &amp;&amp; ./configure &amp;&amp; make &amp;&amp; make install
  
  RUN pip install common python-dateutil cython
  
  RUN pip3 install common python-dateutil cython
  
  # Install numpy 1.11.3 (python2/3)
  RUN git clone --branch v1.11.3 --single-branch https://github.com/numpy/numpy
  COPY /docker_image/site.cfg numpy/
  RUN cd numpy &amp;&amp; python setup.py install
  RUN cd numpy &amp;&amp; python3 setup.py install
  </code></pre>
  
  <p>When I run my build with (clean machine, with nothing in cache):</p>
  
  <pre><code>docker pull quay.io/myorganization/myimage:tag
  </code></pre>
  
  <p>and then run the build with</p>
  
  <pre><code>docker build --cache-from=quay.io/myorganization/myimage:tag -f docker_image/Dockerfile -t quay.io/myorganization/myimage:newtag .
  </code></pre>
  
  <p>the build uses cache until <code>COPY /docker_image/site.cfg numpy/</code> invalidates the cache. My .dockerignore looks like:</p>
  
  <pre><code>.git*
  </code></pre>
  
  <p>so things changing there should not be the problem. If I accidentally omitted some important information needed, please ask and I will promptly provide that. Any ideas on what could cause the cache invalidation on this particular spot would be highly appreciated. </p>
  
  <p>edit: This cache invalidation happens even if I don't change anything in the repo between builds, by doing the following: Build image using tag1, Push image
  to quay.io, then on a clean machine Clone git repo, Pull image (tag1), Build image with tag2. Could it be something that changes in the numpy repo metadata? (Note: --single-branch should not, to my understanding, pull any info about other branches in that repo).</p>