Reputation: 34498
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.
Upvotes: 1
Views: 1134
Reputation: 34498
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'
Upvotes: 3