Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache issue when building a multi-stage image with kaniko

I've setup container images builds in kubernetes using kaniko (version v1.6.0-debug), but I ended up in the following problem when the cache is enabled (/kaniko/executor --cache --cache-repo $CI_REGISTRY_IMAGE/cache).

This is a simplified Dockerfile that explains the issue (the real one has a PHP package.json and package.lock files where new requirements have been added).

FROM busybox:1.33.1 AS builder
WORKDIR /root
COPY testfile testfile

FROM busybox:1.33.1 AS release
WORKDIR /root
COPY --from=builder /root/testfile testfile
RUN cat /root/testfile

If testfile is modified, and the docker image was previously built (and thus all its layers cached in the docker registry), kaniko does not see any modification and uses the cached layer for

COPY --from=builder /root/testfile testfile

The result is that the final docker image provides an old (cached) version of the file testfile instead of the last one.

Any idea how to solve/mitigate this problem? Of course if I remove the cached layers from our docker repository, the image is build correctly, but disable the cache is not an option for me because the builds would be too slow.

like image 531
Davide Madrisan Avatar asked Oct 26 '25 12:10

Davide Madrisan


1 Answers

Upgrading to Kaniko 1.7.0 might solve your problem: https://github.com/GoogleContainerTools/kaniko/pull/1735

like image 53
Tristan Avatar answered Oct 29 '25 07:10

Tristan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!