5

When using buildkit, using the docker cli frontend, I sometimes do not want to use layer-cache, but do want to rely on the newer mount-cache type.

RUN --mount=type=cache,target=...

However running docker build --no-cache seemingly disables both.

Is there a way to choose such that only mount-cache is used during a rebuild ?

hbogert
  • 4,198
  • 5
  • 24
  • 38

1 Answers1

1

You can hack around it by starting the Dockerfile with a layer that will always change, invalidating all following cached layers.

An ARG with always-changing values will do. E.g:

FROM whatever
ARG CACHE_EPOCH
# ... etc
docker build --pull --build-arg CACHE_EPOCH=$(date +%s)

(I have a very similar need https://stackoverflow.com/a/72993502/11715259)

N1ngu
  • 2,862
  • 17
  • 35