title: How can I prevent a Dockerfile instruction from being cached?
body: <p>In my <code>Dockerfile</code> I use <code>curl</code> or <code>ADD</code> to download the latest version of an archive like:</p>
  
  <pre><code>FROM debian:jessie
  ...
  RUN apt-get install -y curl
  ...
  RUN curl -sL http://example.com/latest/archive.tar.gz --output archive.tar.gz
  ...
  ADD http://example.com/latest/archive2.tar.gz
  ...
  </code></pre>
  
  <p>The <code>RUN</code> statement that uses <code>curl</code> or <code>ADD</code> creates its own image layer. That will be used as a cache for future executions of <code>docker build</code>.</p>
  
  <p><strong>Question</strong>: How can I disable caching for that instructions?</p>
  
  <p>It would be great to get something like <strong>cache invalidation</strong> working there. E.g. by using <a href="https://en.wikipedia.org/wiki/HTTP_ETag">HTTP ETags</a> or by querying the <em>last modified</em> header field. That would give the possibility to do a quick check based on the HTTP headers to decide whether a cached layer could be used or not.</p>
  
  <p>I know that some dirty tricks could help e.g. executing a download shell script in the <code>RUN</code> statement instead. Its filename will be changed before the <code>docker build</code> is triggered by our build system. And I could do the HTTP checks inside that script. But then I need to store either the last used <em>ETag</em> or the <em>last modified</em> to a file somewhere. I am wondering whether there is some more clean and <em>native</em> Docker functionality that I could use, here.</p>