Every time I change my Dockerfile, docker re-runs all of my commands even if I change something at the end of the file. The commands are not cached.
-
see also github.com/docker/docker/issues/8330Michael_Scharf– Michael_Scharf2014-10-08 15:57:57 +00:00Commented Oct 8, 2014 at 15:57
1 Answer
In this particular case the image my image was based on contained this statement
ONBUILD ADD . /some/path
That means, no statement in my Dockerfile can be cached when my Dockerfile changes, because the ADD . /some/path is executed just before any of my statements are executed.
In general: if there is an ADD . /some/path statement in the Dockerfile no statement after that statement can be cached, because the change to the Dockerfile invalidates the cache.
My solution was to put the files I want to add into a subdirectory my_data and then add the content of the subdirectory to the path:
ADD my_data /some/path
Unfortunately, adding the Dockerfile to the .dockerignore does not help, because then the docker build cannot execute because it does not find the Dockerfile and you get the error Dockerfile was excluded by .dockerignore pattern 'Dockerfile'