Why is COPY in docker build not detecting updates

I am running a build in a node app and then using artifacts to generate a docker image. The COPY command, which moves my source into place, does not detect changes to the source files after build; its just being used by the cache.

Step 9/12 : COPY server /home/nodejs/app/server ---> Using cache ---> bee2f9334952

Am I doing something wrong with COPY or is there a way to not cache a specific step?

+3


source to share


3 answers


I found this in the docker documentation :

For ADD and COPY instructions, the contents of the file (s) in the image are checked and a checksum is calculated for each file. These checksums do not include the last files with modified time and last access time. During a cache search, the checksum is compared to the checksum in existing images. If something has changed in the file (s), such as content and metadata, then the cache is invalid.



So, as far as I understand, the cache should be invalid. You can use --no-cache = true to be sure. If you get the correct behavior with -no-cache = true and false, you would not find an error and should report it.

+2


source


You can try using ADD instead. This will invalidate the cache for the copy. The bad side is that it will also invalidate the cache for the rest of the commands after it. If your ADD is in its final steps, it shouldn't affect the build process much.



Note. The first ADD command encountered will invalidate the cache for all following instructions from the Dockerfile if the content has changed. This includes invalidating the cache for RUN commands. See the Dockerfile Best Practice Guide for more information. https://docs.docker.com/engine/reference/builder/#add

+1


source


From a Docker perspective, it's just like any other command.

Docker sees that this line has n't changed, so it caches it.

Likewise, if you have a curl command in your Dockerfile, Docker does not fetch the url only to change if it has changed. It checks if the command has changed or not, not the result.

0


source







All Articles