Force docker to always rebuild from a certain layer

Docker has a cache. This saves you a ton of time when the instructions haven't changed. But sometimes it cannot tell if there's a change, e.g. it may be doing a 'pip install git+http://...'. If the package has changed, it doesn't see that.

Sure you could 'docker rmi' a lot of times, like a caveman, but... There has to be a better way.

How about this:

ARG PLANTUML=git+https://${GIT_USER}:${GIT_TOKEN}@mypath@integration
ARG BUILD_FORCE=1
RUN pip3 install ${PLANTUML}

now add --build-arg BUILD_FORCE=$RANDOM to your docker build, and, every single time, this layer will rebuild.

Hah!

Leave a Reply

Your email address will not be published. Required fields are marked *

*