Search code examples
dockercachingapt

Docker cache causes false positive release


I have the following dockerfile:

FROM debian:buster

#Configure apt to look at my Debian repository
COPY ./apt /etc/apt

#Install the software into the image

RUN apt-get update && apt-get -V -y dist-upgrade && apt-get -V -y --allow-unauthenticated --no-install-recommends --allow-downgrades install -f business=1.1-0

ENTRYPOINT ["/usr/sbin/main.sh"]
CMD []

So basically it installs package “business” from version 1.1-0 I have a problem with docker cache, I’m pushing a new code change of package “business” with the same version (1.1-0) [yes I’m overriding versions…] and docker cache is not smart enough to pull the new changed .deb.

It uses the cached layer without my code change :frowning: As workaround, I build with --no-cache but I don’t like this solution because I’m losing the caching mechanism.

Any way to solve that? Can I build with no cache only from specific layer?


Solution

  • Yes you can,

    option a)

    • split your dockerfile , generate a random result in the uncached command:
      RUN apt-get update && apt-get -V -y dist-upgrade 
      RUN head -c 23 /dev/urandom > /.randfile  && apt-get -V -y --allow-unauthenticated --no-install-recommends --allow-downgrades install -f business=1.1-0
      

    option b)

    • use multi-staged builds , but generate the second image with the --no-cache option of docker-compose and docker build ( e.g. do the upgrades in a first pipeline , push as someimage:baseimage, then use FROM someimage:baseimage in the next stage

    option c)