Docker cache wrongly invalidated
Building with docker-compose build
installs a lot of dependencies and build things way too often. This is mainly due to the following line in several Dockerfile
s:
COPY . /pkm-api
Due to this line, each time a file change anywhere in the root folder (even files not from the repository like test logs), then the COPY
line and all those below are invalidated.
Only what is strictly necessary should be copied and dependencies should be installed as soon as possible to avoid repeated installations and compilations.
Here are some pointers documenting this problem:
- https://www.ctl.io/developers/blog/post/more-docker-image-cache-tips/
- https://runnable.com/blog/9-common-dockerfile-mistakes
Steps to reproduce
$ git clone git@gitlab.ow2.org:decoder/pkm-api.git
$ docker-compose build
# [… everything builds …]
$ docker-compose build
# [… everything is retrieved from cache …]
$ echo "build now" >> touch.txt
$ docker-compose build
# [… a lot of things build again while they should not …]