Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is COPY in docker build not detecting updates

Tags:

I run a build on a node application and then use the artifacts to build a docker image. The COPY command that moves my source in place isn't detecting changes to the source files after a build; its just using 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 particular step?

like image 985
Jason Leach Avatar asked Mar 28 '17 15:03

Jason Leach


People also ask

How does copy work in Docker?

COPY and ADD are both Dockerfile instructions that serve a similar purpose. They let you copy files from a specific location into a Docker image. COPY takes in a source and destination. It only lets you copy in a local or directory from your host (the machine-building the Docker image) into the Docker image itself.

Does Docker copy overwrite?

It seems that docker build won't overwrite a file it has previously copied.

How do I automatically update Docker images?

By pushing a new Docker image to your repository, Watchtower will automatically trigger a chain of events to update your running container's base Docker image. When Watchtower detects a new push, it will pull the new base image, gracefully shutdown your running container, and start it back up.


1 Answers

I found this in the Docker documentation:

For the ADD and COPY instructions, the contents of the file(s) in the image are examined and a checksum is calculated for each file. The last-modified and last-accessed times of the file(s) are not considered in these checksums. During the cache lookup, the checksum is compared against the checksum in the existing images. If anything has changed in the file(s), such as the contents and metadata, then the cache is invalidated.

So, as far as I understand, the cache should be invalidated. You can use the --no-cache command-line option to make sure. If you get the correct behavior with --no-cache and an incorrect behavior without it, you would have discovered a bug and should report it.

like image 134
herm Avatar answered Oct 04 '22 19:10

herm