Answers: <p>Check the image history of your two images with <code>docker image history</code>. Pay careful attention to the sha256 checksum of the files being added on the <code>ADD</code> line. Docker performs a checksum on the files, including some of the metadata on these files, so a single byte change or a permission update will result in a cache miss.</p>
  
  <p>Once you've checked this, if it is not your issue, please update the question with the pull command, the build command and full output, and the history command on both images.</p>
  
  <p>Side note: you likely want to use <code>COPY</code> instead of <code>ADD</code> unless you are pulling remote files or extracting a tar file into a directory.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-29T16:18:49.483Z
Answers: I had the same issue. The sha256 of the file in the image and on the filesystem matched, though that doesn't match what shows up in the history with a `file:` prefix. The problem was the `chmod` on the file (apparently GitLab CI checks out files as 666 no 644).
Answers: remram
Answers: CC BY-SA 4.0
Answers: 2018-08-22T11:45:50.430Z
Answers: 2018-08-22T11:45:50.430Z
Answers: BMitch
Body: <p>I've got problem with my Dockerfile. 
  After building an image it is pushed to repository as <code>cache-image</code>, so on next builds I can pull it and use with <code>--cache-from</code>.</p>
  
  <p>Problem is that build stops using cache after first <code>ADD</code> command.</p>
  
  <pre><code>Step 20/30 : WORKDIR $PROJECT_PATH
  ---&gt; Using cache
  ---&gt; d79e2ba28d96
  Step 21/30 : ADD requirements $PROJECT_PATH/requirements
  ---&gt; 6261bb0bd3e6
  Removing intermediate container 26707f4107c9
  </code></pre>
  
  <p>I ran both images (cache and built one) and checked content of requirements directory, they're both identical.
  Whole build is done on Bamboo worker.</p>
  
Tags: <docker><dockerfile><cache>
Title: Docker ADD always invalidates cache
UserDisplayName: Blejwi
ThreadText: # Docker ADD always invalidates cache
  
  (Asked by: username_0 on 2018-08-22)
  
  I've got problem with my Dockerfile.
  After building an image it is pushed to repository as `cache-image`, so on next builds I can pull it and use with `--cache-from`.
  
  Problem is that build stops using cache after first `ADD` command.
  
  ```
  Step 20/30 : WORKDIR $PROJECT_PATH
  ---> Using cache
  ---> d79e2ba28d96
  Step 21/30 : ADD requirements $PROJECT_PATH/requirements
  ---> 6261bb0bd3e6
  Removing intermediate container 26707f4107c9
  
  ```
  
  I ran both images (cache and built one) and checked content of requirements directory, they're both identical.
  Whole build is done on Bamboo worker.
  
  **Tags:** docker, dockerfile, cache
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-22. Score: 4
  
  Check the image history of your two images with `docker image history`. Pay careful attention to the sha256 checksum of the files being added on the `ADD` line. Docker performs a checksum on the files, including some of the metadata on these files, so a single byte change or a permission update will result in a cache miss.
  
  Once you've checked this, if it is not your issue, please update the question with the pull command, the build command and full output, and the history command on both images.
  
  Side note: you likely want to use `COPY` instead of `ADD` unless you are pulling remote files or extracting a tar file into a directory.
  
  > **Comments:**
  > **username_2**: I had the same issue. The sha256 of the file in the image and on the filesystem matched, though that doesn't match what shows up in the history with a `file:` prefix. The problem was the `chmod` on the file (apparently GitLab CI checks out files as 666 no 644).  
  
  ---
  
  